What GCC options should be set to have GCC as strict as possible? (and I do mean as strict as possible) I’m writing in C89 and want my code to be ANSI/ISO compliant.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’d recommend using:
You should compile with
-Oas well as-gas some warnings are only available when the optimizer is used (actually, I usually use-O3for spotting the problems). You might prefer-std=gnu89as that disables fewer extensions in the libraries. OTOH, if you’re coding to strict ANSI C89, maybe you want them disabled. The-ansioption is equivalent to-std=c89but not quite as explicit or flexible.The missing prototypes warns you about functions which are used (or external functions defined) without a prototype in scope. The strict prototypes means you can’t use ’empty parentheses’ for function declarations or definitions (or function pointers); you either need
(void)or the correct argument list. The old style definition spots K&R style function definitions, such as:If you’re lucky, you won’t need to worry about that. I’m not so lucky at work, and I can’t use strict prototypes, much to my chagrin, because there are too many sloppy function pointers around.
See also: What is the best command-line tool to clean up code