Hi, I've been told that it is illegal in ANSI C to use a variable as the size specifier when declaring an array, but I've seen this many times and done it myself with no problems. I can't imagine that's the case, but I couldn't actually find an example in the K&R book where they did that (they do use #defined constants, but not a variable). In Xcode, I create a Standard Tool project, and here is the code:
But, I can't get Xcode/GCC to complain about this, no errors and no warnings. I tried setting the "C Language Dialog" to all settings, including "ANSI", "C89", and "C99" (the Xcode default). This is Leopard Xcode 3.1 with GCC 4.0. Can anyone tell me definitively what the deal is? Am I right about this or is there some compiler setting I've missed that is allowing me to do non-strict ANSI C things?
Additionally, I would like to know what Xcode means by "ANSI" in that setting...aren't "C89" and "C99" both ANSI specifications?
Thanks if you can help clear it up.
Code:
#include <stdio.h>
int main (int argc, const char * argv[]) {
int n = 0;
printf("Enter number of elements: ");
scanf("%d", &n);
int myArray[n]; // <-- Is this legal ANSI C?
int i = 0;
for (i = 0; i < n; i++) {
myArray[n] = i;
}
return 0;
}
Additionally, I would like to know what Xcode means by "ANSI" in that setting...aren't "C89" and "C99" both ANSI specifications?
Thanks if you can help clear it up.