Hi,
Can anybody tell me whether compilation error given by a compiler are specific to it or Standard say something like "This behavior is an Error and it should be reported as Error on all compilers ". Same question for warnings.
Hi,
Can anybody tell me whether compilation error given by a compiler are specific to it or Standard say something like "This behavior is an Error and it should be reported as Error on all compilers ". Same question for warnings.
I don't make much use of anything beyond gcc, but I don't think I have ever seen it generate an error that isn't also a violation of the C standard it is supposed to be using.
Likewise for most but not all of the warnings. Of the later, most are still valid IMO, eg, "use of uninitialized variable" usually indicates a mistake (altho it does not violate a standard). There are a few that seem slightly gratuitous (eg, gcc loves parentheses to excess) but they are not a big deal. There are various ways to limit which warnings you get (try "gcc --help=warnings"), but I have not bothered with this much, and some of them seem to be bunk, eg:
gcc -Warray-bounds
Seems completely ineffective to me (gcc 4.4.5).
Last edited by MK27; 11-14-2011 at 07:50 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
You will get several differing answers to this question. Many compilers work to correctly compile source code written to a certain standard. That does not, however, mean they will report non-standard or even "dangerous" code. In my experience there is a LOT of stuff a compiler will compile, without comment, that causes you no end of grief when testing your code.
Bottom line: "Compiles" does not mean "Works".
When a compiler reports an error... it's telling you it doesn't know what you want from it and cannot continue; it's confused. Generally if you are writing syntactically correct, standards conforming code, you won't get errors but nothing guarantees that. It's really just the compiler saying "I don't know how to do this" which means you need to adjust your code to something it does know how to do.
Warnings are a little different. My compiler (Pelles C) warns me about "old style declarations", deprecated functions and such. These warnings are related to programming standards, but the compiler does continue on to finish the source page. Warnings have to be dealt with intelligently. For example: I get warnings about not using the return value of some functions. That doesn't mean I need to write this massive error trapping routine into every function call, I can and do, choose to ignore the return value of certain functions. I say "Thank you" to the compiler for reminding me, but ultimately I make my own decisions.
However, I'm not aware of anything that holds a compiler (or linker) to any standard error reporting behaviour.