"Undefined Behaviour" or "Non-portable"

J

JKop

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
 
A

Andrew Koenig

JKop said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top