0

I have been looking for related GCC document which allows to declare something like this.

unsigned int subs = 10;
unsigned int array1[subs];

I'm aware such declaration is valid and work using gcc. I would like to get the relevant GCC document that specifies it's okay to declare.

Thanks,

Kitcha
  • 1,641
  • 6
  • 19
  • 20
  • http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html ? – scaryrawr Mar 05 '15 at 18:42
  • 3
    Is also valid in C99 – David Ranieri Mar 05 '15 at 18:43
  • This is not a duplicate, the OP doesn't care how they are implemented. – Iharob Al Asimi Mar 05 '15 at 18:53
  • @iharob: Duplicate means that the other question is a superset and also provides the answer to this. Which it does. The accepted answer has a link to the documentation and additionally shows what the compiler produces. The fact that this question doesn't ask for the second part doesn't make it deserve a duplicated answer. – Ben Voigt Mar 05 '15 at 18:55

2 Answers2

1

From 6.9 Arrays of Variable Length:

As an extension, GCC accepts variable-length arrays as a member of a structure or a union. For example:

    void
    foo (int n)
    {
      struct S { int x[n]; };
    }
Community
  • 1
  • 1
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
0

As stated here

Another GNU extension allows you to declare an array size using variables, rather than only constants.

Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61