In the declaration of the array
#define MAX_VALUE 100
char MY_ARRAY[MAX_VALUE];
there is used an integer constant expression for the size of the array.
In this declaration
int MAX_VALUE=100;
char MY_ARRAY[MAX_VALUE];
there is declared a variable length array. But you may not declare a variable length array with the static storage duration (in particularly in a file scope). You could declare such an array in a block scope if the compiler supports variable length arrays.
Even if you will use the qualifier const
in the declaration of the variable MAX_VALUE
like
const int MAX_VALUE = 100;
it will not produce an integer constant expression according to its definition in the C Standard.
Instead you could write
enum { MAX_VALUE = 100 };
char MY_ARRAY[MAX_VALUE];
From the C Standard (6.6 Constant expressions)
6 An integer constant expression117) shall have integer type and shall
only have operands that are integer constants, enumeration constants,
character constants, sizeof expressions whose results are integer
constants, and floating constants that are the immediate operands of
casts. Cast operators in an integer constant expression shall only
convert arithmetic types to integer types, except as part of an
operand to the sizeof operator.
And (6.7.6.2 Array declarators)
4 If the size is not present, the array type is an incomplete type. If
the size is * instead of being an expression, the array type is a
variable length array type of unspecified size, which can only be used
in declarations or type names with function prototype scope; such
arrays are nonetheless complete types. If the size is an integer
constant expression and the element type has a known constant size,
the array type is not a variable length array type; otherwise, the
array type is a variable length array type. (Variable length arrays
are a conditional feature that implementations need not support; see
6.10.8.3.)
and
2 If an identifier is declared as having a variably modified type, it
shall be an ordinary identifier (as defined in 6.2.3), have no
linkage, and have either block scope or function prototype scope. If
an identifier is declared to be an object with static or thread
storage duration, it shall not have a variable length array type.