Please take a look at HDFql as it can alleviate you from the low-level details of handling HDF5 compound datasets. Using HDFql in C++, your issue can be solved as follows:
// define structure
struct data
{
float col1;
char *col2;
int col3;
HDFQL_VARIABLE_LENGTH col4;
};
// declare variables
char script[1024];
struct data values[2];
int *address;
// create a dataset named "my_dataset" of data type compound of one dimension (size 2) composed of four members (col1, col2, col3 and col4)
HDFql::execute("CREATE DATASET my_dataset AS COMPOUND(col1 AS FLOAT, col2 AS VARCHAR, col3 AS INT, col4 AS VARINT)(2)");
// populate variable "values"
values[0].col1 = 1.1;
values[0].col2 = (char *) malloc(10);
strcpy(values[0].col2, "hello");
values[0].col3 = 1;
address = (int *) malloc(2 * sizeof(int));
*address = 1;
*(address + 1) = 3;
values[0].col4.address = address;
values[0].col4.count = 2;
values[1].col1 = 2.2;
values[1].col2 = (char *) malloc(10);
strcpy(values[1].col2, "world");
values[1].col3 = 2;
address = (int *) malloc(3 * sizeof(int));
*address = 1;
*(address + 1) = 2;
*(address + 2) = 3;
values[1].col4.address = address;
values[1].col4.count = 3;
// insert (i.e. write) values from variable "values" into dataset "my_dataset"
sprintf(script, "INSERT INTO my_dataset VALUES FROM MEMORY %d SIZE %d OFFSET(%d, %d, %d, %d)", HDFql::variableTransientRegister(values), sizeof(struct data), offsetof(struct data, col1), offsetof(struct data, col2), offsetof(struct data, col3), offsetof(struct data, col4));
HDFql::execute(script);
Optionally, you could have the dataset being extendable in its first dimension (by declaring it with an unlimited size) and then write one row, extend the dimension with one unit, write another row, extend the dimension with one unit, etc...
Additional details and examples on how to use HDFql may be found in the reference manual.