Menu

#677 "Integer overflow in expression"

closed-rejected
None
5
2013-05-25
2004-01-11
No

typedef unsigned long LONG;

void main(void)
{
LONG apu=24*60*60;
}

"warning: integer overflow in expression"

It's a little thing but still a very annoying and
unnecessary feature...

SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51
/ds400/hc08 2.3.7 (Jan 11 2004) (MINGW32)

Discussion

  • Erik Petrich

    Erik Petrich - 2004-01-11
    • milestone: --> 100455
     
  • Erik Petrich

    Erik Petrich - 2004-01-11

    Logged In: YES
    user_id=635249

    You would rather not know that apu is initialized with 20864
    rather than 86400?

    An int multiplied by an int is also an int, regardless of
    whatever it may be assigned to. The assignment will cast the
    resultant int to a long, but overflow has already occured.
    If you want the multiplication to be computed with a long
    result, at least one of operands should be long. For example:

    LONG apu = 24*60*60UL;
    or
    LONG apu = 24*60*(LONG)60;

     
  • Bernhard Held

    Bernhard Held - 2004-01-11
    • milestone: 100455 --> unreproducable
    • assigned_to: nobody --> bernhardheld
    • status: open --> closed-rejected
     
  • Bernhard Held

    Bernhard Held - 2004-01-11

    Logged In: YES
    user_id=203539

    You'd better be happy about this warning instead of complaining
    about it!

     
  • Mika Rasimus

    Mika Rasimus - 2004-01-12

    Logged In: YES
    user_id=928028

    Oops... My mistake... again... I didn't think it works that way.
    With my previous compiler I have managed to avoid the
    problem just with a blind luck :)

    Ok... I don't think it is annoying behaviour at all... Unlike that
    ANSI-C-thing of expanding an explicitly defined unsigned char
    to a signed int. There must be a good reason for that but I
    can't figure it out =P

    Any way... No matter how much I complain about ANSI-
    features that I have never heard of, you still keep up good
    work :)

     

Log in to post a comment.