You probably created a VLA instead.
This doesn't work.
Code:
$ cat bar.c
#include <stdio.h>
const int size = 10;
int array[size];
int main ( ) {
return 0;
}
$ gcc bar.c
bar.c:4: error: variably modified ‘array’ at file scope
> but I would still use a macro for something like that
Why?
If you don't like the type checking argument, how about the freedom from side effects argument?
Code:
$ cat bar.c
#include <stdio.h>
#define max(a,b) a > b ? a : b
int main ( ) {
char *p = max("hello","world");
int a = 10, b = 20;
int c = max(a++,b++);
printf("%s\n",p);
printf("%d %d\n",a,b);
return 0;
}
$ gcc bar.c
$ ./a.out
hello
11 22
> because if you screw it up in C, after the PP inserts the macro into the code, you'll get a compilation error soon after.
Oddly, doing max on two strings produced no such errors.