problems using the -ansi switch in MinGW 3.4.5
Question
I was reading about the flags used in gcc, and read a reccommendation to use gcc -ansi -pedantic -Wall file1 [file2 [file3...]] -o output
. For the quality of my code's sake, to keep it standard, and get all the warnings about it.
Well, about compiling with -ansi...
If I include <stdlib.h>
, gcc gives me this error:
In file included from ansi.c:2:
C:/c/bin/../lib/gcc/mingw32/3.4.5/../../../../include/stdlib.h:317: error: syntax error before "double"
That line in is this:
inline double __cdecl __MINGW_NOTHROW strtod (const char* __restrict__ __nptr, char** __restrict__ __endptr)
{ return __strtod(__nptr, __endptr); }
does inline
not exist in C? Shouldn't a "standard" header be standard ansi? Should I just remove the inline or avoid compiling with stdlib.h (I can't really remember what's in stdlib right now)?
Update
from reading the link which Adam posted I found out that "inline" isn't a keyword in C89, and C89 is what is enforced with the -ansi switch. I had to change it to __inline__
which is, I suppose, a MinGW macro.
Thanks for the help.
Solution
It seems a known issue in mingw: link to archive mingw mailing list
It tells that inline is not part of the c89 standard (as -ansi force it) and it should be replaced with __inline__
instead
If you read next e-mails, someone tells he has fix this bug directly in the cvs. Check out the new code and have a look (?) then tell us. :-)
OTHER TIPS
inline is not part of what gcc 3.4.5 considers to be ANSI C - it is part of C99, I think Can you confirm which version of gcc you are using?
I've run into this problem before when compiling to a specific standard. On a Linux system I was compiling to, the pthread rwlock headers weren't c99 compliant (or weren't ifndef'd in). You have to be careful in these cases, and checking the output of the preprocessor can sometimes help in these cases.