Thread: Compilers and warnings

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    Compilers and warnings

    if a program compiles and runs as you want but with warnings at compile time why should we take notice of the warnings? just generally wanting to know about reasons for warnings, because some seem very innocuous and especially if you know why they are there, i used to get them from using getch() and then not doing anything with the variable, but getch() was doing what i wanted, ie stopping program.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you understand why you are getting the warning, then it's sort of OK to ignore it. In the case of using getch() to stop the program and then not using the variable, you can always NOT assign any variable, e.g.
    Code:
    // instead of 
    ch = getch();
    // use
    getch(); 
    // That _may_ give you a warning that you are ignoring the result of the function, then use:
    (void) getch();
    I have worked on projects using "-Werror" in gcc, which means that if there are warnings, it's the same as any error - no object code generated. Warnings are there for a reason. If you understand the reason, then you can, occasionally, ignore the warning.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    hey nice one, i thought you would be first to reply there, what with your signature and all! Yea, i have heard of the compilers where a warning will stop compile, i don't think i would get much work to run if that was the case for me haha, but really, for me its just i like to get rid of the errors as a kind of 'housekeeping' they annoy me messing up my nice little compile report!

    are some errors a throwback to where memory was more 'expensive' so unused varialbes or values get flagged?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Sort of, but unused variables are often a sign that you've done something else wrong - e.g. you read in x, but you never use it in the calculation. The compiler is trying to say "well, perhaps you should be using x for something".

    Or this:
    Code:
    int err;
    
    err = somefunc(...);
    // Oops, we forgot to check err...
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't recommend ignoring warnings. They're there for a reason. What you should do is strive to understand them and know how to silence them. By silencing them, that (often) means you know how to make it "right."
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    yes, i don't like to have any errors even if i know why they are there, and i reckon some better programming practices have defo been picked up through learning how to clear them up.

    with getch() i seem to remember if i tested the value input with an IF statement, for (Q)uit say, it still gave a warning at compile about a value that is never used, (but to me it is used if the statement is true) i don't remember though, perhaps that one was ok.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rogster001 View Post
    with getch() i seem to remember if i tested the value input with an IF statement, for (Q)uit say, it still gave a warning at compile about a value that is never used, (but to me it is used if the statement is true) i don't remember though, perhaps that one was ok.
    I'm pretty sure that's your memory having "bit errors".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to delete void* pointer
    By benshi in forum C++ Programming
    Replies: 44
    Last Post: 12-21-2007, 06:17 PM
  2. Problem in the optimized / release build
    By g4j31a5 in forum C++ Programming
    Replies: 10
    Last Post: 10-10-2006, 06:32 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Warnings in gnu compilers
    By vanye in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2003, 10:18 PM
  5. can someone check this out and let me know ?
    By javaz in forum C Programming
    Replies: 5
    Last Post: 01-21-2002, 02:13 PM