I
Ian Pilcher
I'm trying to figure out if an increment to a variable of an integer
type, followed by a decrement, (or vice versa) is guaranteed to restore
the variable to its initial value, even if the first operation causes
the variable to overflow/underflow.
In other words, if foo_t is an integer type, are the following two
functions guaranteed to *always* return a non-zero value?
int check_overflow(foo_t f)
{
foo_t g = f;
g++;
g--;
return (f == g);
}
int check_underflow(foo_t f)
{
foo_t g = f;
g--;
g++;
return (f == g);
}
Thanks!
type, followed by a decrement, (or vice versa) is guaranteed to restore
the variable to its initial value, even if the first operation causes
the variable to overflow/underflow.
In other words, if foo_t is an integer type, are the following two
functions guaranteed to *always* return a non-zero value?
int check_overflow(foo_t f)
{
foo_t g = f;
g++;
g--;
return (f == g);
}
int check_underflow(foo_t f)
{
foo_t g = f;
g--;
g++;
return (f == g);
}
Thanks!