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,

4
  • gcc.gnu.org/onlinedocs/gcc/Variable-Length.html ? Commented Mar 5, 2015 at 18:42
  • 3
    Is also valid in C99 Commented Mar 5, 2015 at 18:43
  • This is not a duplicate, the OP doesn't care how they are implemented. Commented Mar 5, 2015 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. Commented Mar 5, 2015 at 18:55

2 Answers 2

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]; };
    }
Sign up to request clarification or add additional context in comments.

2 Comments

I don't think this is the question.
@iharob: As requested in the question, this is the "relevant GCC document that specifies it's okay to declare".
0

As stated here

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.