Topic: Undefined Behaviour" or "Non-portable
Author: NULL@NULL.NULL (JKop)
Date: Wed, 4 Aug 2004 20:19:03 GMT Raw View
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
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: do-not-spam-benh@bwsint.com (Ben Hutchings)
Date: Thu, 5 Aug 2004 17:27:44 GMT Raw View
JKop wrote:
> 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
Right, but only arithmetic operations can overflow, not conversions.
> 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 and therefore non-portable.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: radekg@b-runner.nospam.org (Radoslaw Grzanka)
Date: Thu, 5 Aug 2004 18:03:24 GMT Raw View
Dnia Wed, 04 Aug 2004 20:19:03 +0000, JKop napisa=B3(a):
> Would you classify the following code as "Undefined Behaviour" or as "N=
on-
> portable"?
>=20
> signed main()
> {
> signed char chedder =3D 130;
> }
>=20
>=20
> Relevant information:
>=20
> 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
>=20
> If the program is run on a system with a 9-Bit char, then there's no=20
> overflow, and as such there's no Undefined Behaviour.
>=20
> But overall would you classify it as "Undefined Behaviour" or "Non-
> portable"?
If 2) is right (I didn't remember about that) I would say both. It is
non-portable from machines with more than 8 bits per char and undefined
behaviour on machines with 8 bits and less per char.
Radoslaw.
--=20
"Oceniaj=B1 mnie, cho=E6 nic o mnie nie wiedz=B1. To dlatego jestem sam" =
- Shrek
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
e-mail: sad[na]rpg[kropka]pl JID: radekg[na]jabber[kropka]atman[kropka=
]pl
L:C++ E+++ T-- !R P+++ D G++ F:ADoM RL--- !RLA W:CP Q++ AI++ RN+ Hp- Re++=
S+
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]