Thread: Errors and warnings

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    28

    Errors and 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.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    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

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by _arjun View Post
    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.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program crashing despite no errors and warnings
    By yohanevindra in forum C Programming
    Replies: 10
    Last Post: 09-07-2010, 10:40 PM
  2. How do I fix these annoying warnings and errors?
    By zyphirr in forum C Programming
    Replies: 18
    Last Post: 11-12-2008, 06:19 PM
  3. Definitions for gcc errors and warnings?
    By cpjust in forum C Programming
    Replies: 12
    Last Post: 10-04-2007, 09:18 AM
  4. Template Warnings/Errors... C4346
    By Peter5897 in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2007, 01:17 PM
  5. Some errors and warnings i dont understand
    By lakai02 in forum C Programming
    Replies: 6
    Last Post: 10-18-2002, 11:16 AM

Tags for this Thread