user56538: This sketch does not compile in the Arduino IDE
void setup() {
  // put your setup code here, to run once:

}

struct test {
  int i;
  char variable[];
};

typedef struct test test;

test t = {
  0, "hi"
};

void loop() {
  // put your main code here, to run repeatedly:

}

Arduino throws 
sketch_may09a:16: error: initializer-string for array of chars is too long [-fpermissive]

 };

 ^

exit status 1
initializer-string for array of chars is too long [-fpermissive]

However compiling with g++ works just fine. How can I fix it? Or is there a principle reason why flexible array members are not supported?

user23841: Maybe you've compiled it in g++ without any warnings enabled (or maybe it yeld warnings but was compiled). The arduino uses flags to consider all warnings as an error, so it won't compile. It may wary for different platforms, I've got -fpermissive used (and I don't like it at all).
That's because size of struct must be known compile time and if you provide char variable[]; you'll get zero sized array. Therefore anything biiger than nothing you'll try to initialize for is too long.
Maybe you're looking for something like this:
struct test {
  int a;  
  const char * ptr;
};

test paramx {1, "some string"};
test paramy {2, "another string"};

test array[] = {{3,"three"}, {4, "four"}, {5,"five"}};


user55899: Flexible array member is a C feature. It does not exist in C++. On top of that, the way you use it to declare and initialize a static struct of flexible size is non-standard even for C. 
However, GNU-C language supports it as an extension. Also, newer versions of GCC (6 and higher) allow this in GNU-C++ code as an extension as well. But GCC 5.4.0 used by Arduino IDE doesn't support this non-standard feature in C++ code.
If you flip through different GCC versions on Godbolt (https://godbolt.org/z/Iul7hD) you'll see that support for this feature has always been present in C code, but for C++ code it first appeared in GCC 6.
This is why you were able to compile it with your standalone g++ compiler (which is apparently a much later version), but were unable to compile it in Arduino IDE.
It means that if you really want this non-standard code to compile in the current version of Arduino IDE, you have to place it into a .c file. Or just specify the array size explicitly.

56538: <p>This sketch does not compile in the Arduino IDE</p>

<pre><code>void setup() {
  // put your setup code here, to run once:

}

struct test {
  int i;
  char variable[];
};

typedef struct test test;

test t = {
  0, "hi"
};

void loop() {
  // put your main code here, to run repeatedly:

}
</code></pre>

<p>Arduino throws </p>

<pre><code>sketch_may09a:16: error: initializer-string for array of chars is too long [-fpermissive]

 };

 ^

exit status 1
initializer-string for array of chars is too long [-fpermissive]
</code></pre>

<p>However compiling with g++ works just fine. How can I fix it? Or is there a principle reason why flexible array members are not supported?</p>
 23841: <p>Maybe you've compiled it in g++ without any warnings enabled (or maybe it yeld warnings but was compiled). The arduino uses flags to consider all warnings as an error, so it won't compile. It may wary for different platforms, I've got -fpermissive used (and I don't like it at all).</p>

<p>That's because size of struct must be known compile time and if you provide <code>char variable[];</code> you'll get zero sized array. Therefore anything biiger than nothing you'll try to initialize for is too long.</p>

<p>Maybe you're looking for something like this:</p>

<pre><code>struct test {
  int a;  
  const char * ptr;
};

test paramx {1, "some string"};
test paramy {2, "another string"};

test array[] = {{3,"three"}, {4, "four"}, {5,"five"}};
</code></pre>
 55899: <p><em>Flexible array member</em> is a C feature. It does not exist in C++. On top of that, the way you use it to declare and initialize a static struct of flexible size is non-standard even for C. </p>

<p><strong>However</strong>, GNU-C language supports it as an extension. Also, newer versions of GCC (6 and higher) allow this in GNU-C++ code as an extension as well. But GCC 5.4.0 used by Arduino IDE doesn't support this non-standard feature in C++ code.</p>

<p>If you flip through different GCC versions on Godbolt (<a href="https://godbolt.org/z/Iul7hD" rel="nofollow noreferrer">https://godbolt.org/z/Iul7hD</a>) you'll see that support for this feature has always been present in C code, but for C++ code it first appeared in GCC 6.</p>

<p>This is why you were able to compile it with your standalone <code>g++</code> compiler (which is apparently a much later version), but were unable to compile it in Arduino IDE.</p>

<p>It means that if you really want this non-standard code to compile in the current version of Arduino IDE, you have to place it into a <code>.c</code> file. Or just specify the array size explicitly.</p>
