Return structure with flexible array member

后端 未结 7 1843
栀梦
栀梦 2021-01-15 03:23

I need to return a structure with a flexible array member from a C function but can\'t figure out why it doesn\'t compile. I know that returning arrays can be achieved by en

7条回答
  •  清酒与你
    2021-01-15 04:07

    struct data_array * test(long length) {
        struct data_array *a = calloc(1,sizeof(struct data_array) + length*sizeof(double));
        a->length = length;
        return a;
    }
    

提交回复
热议问题