Topic: overflow of integral types - defeined behavior?


Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: Mon, 16 Jul 2001 17:02:48 GMT
Raw View
On Thu, 12 Jul 2001 00:12:15 GMT, Jack Klein <jackklein@spamcop.net>
wrote:

>
>For floating point types and signed integer types the behavior on
>overflow is undefined.  No diagnostic is required at compiler time for
>undefined behavior.
>

Is the reason here that the implementation of signed types is
implementation defined? I always thought that signed means 2's
complement.


>There is no overflow possible with the unsigned integer types.  The
>result is the "true" result modulo TYPE_MAX + 1.

I can understand that - thanks.


------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: MikeAlpha@NoSpam_csi.com (Martin Aupperle)
Date: Wed, 11 Jul 2001 17:04:30 GMT
Raw View
I have a question about overflow of arithmetic types.

Is the expression

 T t = maxT + 1;

well defined for arithmetic types T? maxT should be the literal with
the larges representable value for type t.

What is the compiler supposed to do in such a situation? Is a
warning/error message required?

Thanks - Martin


------------------------------------------------
Martin Aupperle
MikeAlpha@NoSpam_csi.com
(remove NoSpam_)
------------------------------------------------

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Jack Klein <jackklein@spamcop.net>
Date: Thu, 12 Jul 2001 00:12:15 GMT
Raw View
On Wed, 11 Jul 2001 17:04:30 GMT, MikeAlpha@NoSpam_csi.com (Martin
Aupperle) wrote in comp.std.c++:

>
> I have a question about overflow of arithmetic types.
>
> Is the expression
>
>  T t = maxT + 1;
>
> well defined for arithmetic types T? maxT should be the literal with
> the larges representable value for type t.
>
> What is the compiler supposed to do in such a situation? Is a
> warning/error message required?
>
> Thanks - Martin

For floating point types and signed integer types the behavior on
overflow is undefined.  No diagnostic is required at compiler time for
undefined behavior.

There is no overflow possible with the unsigned integer types.  The
result is the "true" result modulo TYPE_MAX + 1.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

---
[ 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.research.att.com/~austern/csc/faq.html                ]