Re: C return a++ - is it safe?



RoS wrote:

<snip>

you and other seems not understand the esistance of variables that
*can not* overflow e.g. size_t; or
int, unsigned, float, double etc in financial calculis etc etc

No. Signed types can overflow.

if some of that variables has an overflow it has to rappresent an
error number (eg: INT_MAX for +overflow and INT_MIN for -overflow)
so detect errors in run time is more easy

INT_MAX and INT_MIN are valid values. Using them to represent overflow
is, IMHO, not wise.

for an unsigned thype the aritimetic is very easy

0..UMAX
....
0..UMAX-1 is ok
UMAX is an error

No. Uxxx_MAX is a valid value of that type.

.



Relevant Pages

  • Re: [PATCH 2/2] lib: vsprintf.c remove macros defining strict string functions
    ... required at the end of a string (nul-terminated or newline). ... overflow of the signed types. ...
    (Linux-Kernel)
  • Re: Incrementing variables past limits
    ... > Does the ANSI standard say anything about incrementing variables past ... For unsigned types, overflow has well-defined behavior; ... For signed types, overflow causes undefined behavior. ...
    (comp.lang.c)
  • Re: questions of unsigned int, function prototypes
    ... >For a unsigned int used as a counter, ... Unlike signed types, the C Standard fully specifies what ... happens to overflow for unsigned integers. ... >What're purposes about using function prototypes in C? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: __TIME_MIN/__TIME_MAX
    ... I'll have to double-check. ... > undefined (similar to overflow with signed types). ... FreeBSD UNIX ...
    (freebsd-arch)
  • Re: css problem (float)
    ... element in the normal flow that establishes a new block formatting ... not overlap any floats in the same block formatting context as the ... cells, positioned things, things with overflow other than visible. ... float: right; ...
    (alt.html)