Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Specifying dimension of array in function and outside function does not give same result

This compiles fine under C99

const int DIM;
int main() {
 int tab[DIM];
}

while the following gives the error

int tab[DIM];
int main() {
}

error: variably modified tab at file scope

Why?

I know how to fix it :

#define DIM 10

But this does not provide the answer to my question Thanks for your reply

Answer*

Draft saved
Draft discarded
Cancel
4
  • Do not cite text from the C standard drafts as text from the official standard. Both what was said to be the "final working draft," N3054, and some later draft, N3096, differ considerably from the published standard, including the insertion of addition subclauses, making the clause numbering different between the drafts and the official standard. After a committee does its work, there is some additional balloting process that may result in changes to a standard before publication. Also, you had text cited from the standard that did not appear in the drafts or the standard. Commented Nov 27, 2024 at 21:46
  • @EricPostpischil I cited N3088. In any case nothing was changed relative to variable length arrays in the provided quites. Commented Nov 27, 2024 at 21:50
  • You may have quoted from draft N3088, but you cited the standard. That is the wrong thing to do. When quoting material, you should state the actual source it came from. That means, if it is from a draft, then saying it is from a draft, and which number, or, if it is from the official standard, then saying it is from the standard. The clause numbers changed, one word changed, and you had additional words in the quote that were apparently your own, not in the draft or the standard. Commented Nov 27, 2024 at 21:58
  • @EricPostpischil TMaybe I made a typo when combined the quotes and my text. Commented Nov 28, 2024 at 5:06

lang-c

AltStyle によって変換されたページ (->オリジナル) /