Thread: Advice on removing valid (but minor) compiler warnings

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    46
    Quote Originally Posted by MK27 View Post
    But if you add a cast the warning goes away?
    Yes.
    But as for checking the value with your ternary operation, that will not matter to the compiler* one way or the other.
    I didn't think it would. But having had my attention drawn to this line of code that (I believe) theoretically could overflow aren't I better off doing something about it?

    If the code would actually 'peg' at 256 instead of wrapping round then that's a different matter, but C doesn't do that, does it?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by PaulBlay View Post
    But having had my attention drawn to this line of code that (I believe) theoretically could overflow aren't I better off doing something about it?
    I don't *think* you can cause an overflow with arithmetic, the values just wrap around.

    If you aren't sure that an error can't happen, then you definitely need to account for that in your programming. Probably getting scolded about type mismatches is enough to create a (pavlovian*)response eventually, and maybe just adding the cast will get you to think about the implications, so it's all good. I use gcc -Wall and I have never seen a compiler warning that could not be dealt with; they are not irrational and thank the gods for them.

    As long as you understand that it's adding the cast, and not the error check, that cues it.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  2. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM