Reputation: 4368
I need that code for my program to have colors. But it wont compile if i use -pedantic. Is there a way around this? its btw
gcc -pedantic MP1.c -o hahah MP1.c: In function `main': MP1.c:65: warning: ISO C90 forbids mixed declarations and code MP1.c:686:30: warning: (this will be reported only once per input file)
line 65:
int originalAttrs = ConsoleInfo.wAttributes;
Upvotes: 1
Views: 6665
Reputation: 263277
Either fix the code so it complies with the C90 standard (as hmjd's answer suggests), or tell gcc to use a newer version of the standard.
C does permit mixed declarations and statements starting with the C99 standard.
If you use
gcc -std=c99 -pedantic
or
gcc -std=c11 -pedantic
it should work.
Upvotes: 0
Reputation: 121971
Move declaration of originalAttrs
to the top of the scope in which it is used. The error is unrelated to use of ConsoleInfo.wAttributes
but to the location of the declaration of originalAttrs
. Without seeing the entire code, it is probably something like:
printf("hello\n"); /* For example. */
int originalAttrs = ConsoleInfo.wAttributes;
To fix:
int originalAttrs;
printf("hello\n"); /* For example. */
originalAttrs = ConsoleInfo.wAttributes;
Upvotes: 3