"Undefined Behaviour" or "Non-portable"

Discussion in 'C++' started by JKop, Aug 4, 2004.

  1. JKop

    JKop Guest

    Would you classify the following code as "Undefined Behaviour" or as "Non-
    portable"?

    signed main()
    {
    signed char chedder = 130;
    }


    Relevant information:

    1) Minimum range for a signed char: -127 to 127
    2) Overflow for a signed integral type is Undefined Behaviour
    3) There's no maximum range for a signed char

    If the program is run on a system with a 9-Bit char, then there's no
    overflow, and as such there's no Undefined Behaviour.

    But overall would you classify it as "Undefined Behaviour" or "Non-
    portable"?


    -JKop




    -JKop
     
    JKop, Aug 4, 2004
    #1
    1. Advertising

  2. "JKop" <> wrote in message
    news:OnaQc.24394$...
    > Would you classify the following code as "Undefined Behaviour" or as "Non-
    > portable"?
    >
    > signed main()
    > {
    > signed char chedder = 130;
    > }
    >
    >
    > Relevant information:
    >
    > 1) Minimum range for a signed char: -127 to 127
    > 2) Overflow for a signed integral type is Undefined Behaviour
    > 3) There's no maximum range for a signed char
    >
    > If the program is run on a system with a 9-Bit char, then there's no
    > overflow, and as such there's no Undefined Behaviour.
    >
    > But overall would you classify it as "Undefined Behaviour" or "Non-
    > portable"?


    Implementation-defined. If the range of signed char does not include 130,
    then the result of assigning 130 to a signed char variable is
    implementation-defined, which means that the implementation is required to
    document its actual behavior.
     
    Andrew Koenig, Aug 4, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eli Bendersky
    Replies:
    1
    Views:
    1,181
    Mike Treseler
    Mar 1, 2006
  2. Dan Cernat

    undefined behaviour

    Dan Cernat, Nov 11, 2003, in forum: C++
    Replies:
    1
    Views:
    358
    Josh Sebastian
    Nov 11, 2003
  3. Gautam

    Non Portable C

    Gautam, May 9, 2004, in forum: C Programming
    Replies:
    3
    Views:
    357
    Joe Wright
    May 9, 2004
  4. Gautam

    Non Portable C

    Gautam, May 9, 2004, in forum: C Programming
    Replies:
    0
    Views:
    366
    Gautam
    May 9, 2004
  5. Replies:
    6
    Views:
    285
    Philip Potter
    Apr 10, 2008
Loading...

Share This Page