Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > "Undefined Behaviour" or "Non-portable"

Reply
Thread Tools

"Undefined Behaviour" or "Non-portable"

 
 
JKop
Guest
Posts: n/a
 
      08-04-2004
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
 
Reply With Quote
 
 
 
 
Andrew Koenig
Guest
Posts: n/a
 
      08-04-2004
"JKop" <(E-Mail Removed)> wrote in message
news:OnaQc.24394$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments