[sane-devel] C undefined operations in sane-backends-1.0.7-beta1
Ingo Wilken
Ingo.Wilken@Informatik.Uni-Oldenburg.DE
Fri, 25 Jan 2002 15:53:24 +0100 (MET)
> let's have a look at the warnings from the Plustek backend.
> The lines that produce the problem include the following statement:
> _SWAP(x,y) (x)^=(y)^=(x)^=(y)
> So what? Where's the problem here?
From the comp.lang.c FAQ:
Status: O
# 3.3b: Here's a slick expression:
#
# a ^= b ^= a ^= b
#
# It swaps a and b without using a temporary.
#
# A: Not portably, it doesn't. It attempts to modify the variable a
# twice between sequence points, so its behavior is undefined.
#
# For example, it has been reported that when given the code
#
# int a = 123, b = 7654;
# a ^= b ^= a ^= b;
#
# the SCO Optimizing C compiler (icc) sets b to 123 and a to 0.
#
# See also questions 3.1, 3.8, 10.3, and 20.15c.
Regards,
Ingo