In C89/C90, you can't interleave declarations and statements, such as putting the int x[size];
declaration (definition) after the scanf()
— even if you change the dimension to a compile time constant. In C89/C90, declarations within a function must appear at the start of a compound statement (immediately after the {
and before the first statement within the compound statement; compound statements can be nested within a function body).
In C89/C90, you cannot use a variable length array — so the int x[size];
definition is not legal because size
is not a compile time constant.
C99 compilers are required to support both declarations at (almost) arbitrary points in a function (they still can't be preceded by a label) and variable length array (VLA) definitions.
C11 compilers are required to support variable definitions (almost) anywhere in a function. C11 compilers may optionally support VLAs (§6.10.8.3 Conditional feature macros and §6.7.6.2 Array declarators), and should define __STDC_NO_VLA__
if they do not support them.
C18 is equivalent to C11 in all aspects of this discussion.
When it is released, C23 will require that compilers accept VLA specifications as function arguments but will not require that local variables can be defined as VLAs. You will be able to dynamically allocate VLAs as now — and on restrictive compilers, will be required to do so.
Just for the record:
- C89 is ANSI X3.159-1989
- C90 is ISO 9899-1990 — the ANSI version of which was marked with "revision and redesignation of ANSI X3.159-1989". The primary difference was in the section numbers for the language and the library.
- C99 is ISO/IEC 9899:1999
- C11 is ISO/IEC 9899:2011
- C18 is ISO/IEC 9899:2018
- C23 will be either ISO/IEC 9899:2023 or 9899:2024.
Of course, the only unusual thing about X3.159-1989 was that it was published by ANSI before there was an ISO standard. However, ANSI has adopted each subsequent ISO standard too, as have other national standards bodies such as BSI (British Standards Institute) and DIN (Deutsches Institut für Normung or German Institute for Standardization).
There was also an Amendment 1 (to ISO 9899:1990) finalized in 1994 and published in 1995. That added headers and introduced digraphs and made sundry other changes. It is almost never considered separately, especially not now, 25 years later.
Note that GCC treats the -ansi
option as equivalent to -std=c90
, which can lead to confusion over terminology. ANSI originally published 'the ANSI C standard' a year or so before ISO did, but the intent was always to have a common standard, and ANSI endorsed the ISO 9899:1990 standard when it was published.