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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    But if you add a cast the warning goes away?
    Code:
    m_ptr->confused += 10 + (unsigned char)randint0(p_ptr->lev) / 5;
    I notice you used (byte) in your alt version, which should work too I guess.

    That's certainly very common; there are tons of standard functions that want a "const char*" and you can use a cast to eliminate those warnings if your parameter is really just a "char*".

    But as for checking the value with your ternary operation, that will not matter to the compiler* one way or the other. It may be a good idea anyway, of course. But if you know the execution is such that data loss (or wrap-around) will actually be impossible, then it's totally unnecessary; technically plain old arithmetic could be used to wrap around int values too, but generally you don't need to check for that possibility.

    * if you think about it you should be able to intuit why it CANNOT matter to the compiler, which is to say it can't issue a warning because you did or did not add an error checking routine. Although the warning may prompt you to write one, that will not change the warning...
    Last edited by MK27; 04-20-2009 at 09:53 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

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