gcc error


if you use const variable to define an array out of main, like that:

1
2
3
4
5
6
7
8
9
10
11
12
#include<stdio.h>
const int MAX= 100010;
char s[MAX];
int main(){
while(fgets(s,MAX,stdin) != NULL){
puts(s);
}
return 0;
}

gcc will report : Error: variably modified ‘s’ at file scope. But if you use #define, it will be ok. like that:

1
2
3
4
5
6
7
8
9
10
11
12
#include<stdio.h>
#define MAX 100010
char s[MAX];
int main(){
while(fgets(s,MAX,stdin) != NULL){
puts(s);
}
return 0;
}

If you do not want to use #define macro, and you will use a small array, you can use a const variable to define the array size, like that:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include<stdio.h>
//#define MAX 100010
//char s[MAX];
int main(){
const int MAX= 30;
char s[MAX];
while(fgets(s,MAX,stdin) != NULL){
puts(s);
}
return 0;
}

But if you will allocate a big array in main function, gcc will report a warning :warning: overflow in implicit constant conversion