2

My code contains the following line:

int counts[config.max_c];

I was surprised to see that it compiled without issue using default gcc without any flags. According to man gcc the default standard for c code is gnu89. Does this standard support this type of array initialisation, and if so where can I find a reference?

Flash
  • 15,945
  • 13
  • 70
  • 98
  • 2
    Quote from the man pages: "gnu89 - GNU dialect of ISO C90 (including some C99 features). This is the default for C code." with some c99 features, vlas are included(as stated in the [man pages](https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html) of vlas. sadly, you will have to look up every feature you are interested in and see if it is supported. – hellerve May 25 '14 at 09:53
  • Just to add to +Carson's comment, to clear things up, `gnu89` (which us an alias for `gnu90`) isn't considered a _standard_, just a _'dialect'_, which is why the answers are as they are – RastaJedi Sep 19 '16 at 05:34

2 Answers2

5

Does this standard support this type of array initialisation, and if so where can I find a reference?

No. It doesn't support variable length arrays.

Variable-length automatic arrays are allowed in ISO C99, and as an extension GCC.
Although you are compiling your code in C89, it compiles without error because of the GCC extension.

haccks
  • 104,019
  • 25
  • 176
  • 264
1

gcc's default dialect to use is C90.

For C90 gcc supports VLAs as an extension.

alk
  • 69,737
  • 10
  • 105
  • 255
  • GCC's default (apparently only up until recent versions, where they finally made the switch to `gnu11` by default, though I don't think I've used these versions yet) is to use the `gnu90` (`gnu89` is exactly the same) dialect for C code, which means, at least under GCC, that it will be supported by default (via the extensions). I think it is supported even with `-std=c90` (same as `c89`), since that only turns off certain extensions (same result as `-ansi`) unless you use `-pedantic`, but don't quote me on that. – RastaJedi Sep 19 '16 at 05:45