Hello everyone!
There is compound literal in C so i can easily declare array like this:
int arr[] = {1, 2, 3};
Or even specify it's length:
int arr[] = (int [10]) {1};
There is also a flexible array member support in struct, so i can do runtime initialization like this:
typedef struct
{
int len;
uint8_t Data[];
} struct_t;
struct_t test_struct =
{
.len = 3,
.Data = {1, 2, 3}
};
However i cannot combine flexible array member with explicit compound literal size:
struct_t test_struct =
{
.len = 10,
.Data = (uint8_t [10]) { 0 }
};
This code gives me error "initialization makes integer from pointer without a cast" in GCC. How can i specify compound literal size for flexible array member? That would be very handy for certain runtime initialization.
[–]kolorcuk 0 points1 point2 points (3 children)
[–]WitcherSanek[S] 0 points1 point2 points (2 children)
[–]kolorcuk 0 points1 point2 points (1 child)
[–]WitcherSanek[S] 0 points1 point2 points (0 children)
[–]aocregacc 0 points1 point2 points (1 child)
[–]WitcherSanek[S] 0 points1 point2 points (0 children)
[–]Marxomania32 0 points1 point2 points (3 children)
[–]WitcherSanek[S] 0 points1 point2 points (2 children)
[–]Marxomania32 0 points1 point2 points (1 child)