Re: [PATCH 1/5] add SWAP macro
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jan 31, 2017, 12:03 UTC
- Message-ID
- <alpine.DEB.2.20.1701311302310.3469@virtualbox>
- In-Reply-To
- <77098ac8-1084-a5c4-a5e6-fb382e3dc3a0@web.de>
Hi René,
On Mon, 30 Jan 2017, René Scharfe wrote:
Show 9 quoted lines
> Am 30.01.2017 um 22:03 schrieb Johannes Schindelin:
> > It is curious, though, that an expression like "sizeof(a++)" would not
> > be rejected.
>
> Clang normally warns about something like this ("warning: expression
> with side effects has no effect in an unevaluated context
> [-Wunevaluated-expression]"), but not if the code is part of a macro. I
> don't know if that's intended, but it sure is helpful in the case of
> SWAP.Thank you for clarifying.
Show 6 quoted lines
> > Further, what would SWAP(a++, b) do? Swap a and b, and *then* > > increment a? > > That might be a valid expectation, but GCC says "error: lvalue required > as unary '&' operand" and clang puts it "error: cannot take the address > of an rvalue of type".
Okay, now we know what the tool says.
I would like to take a step back and state that it does not make much sense to support SWAP(a++, b), as it is confusing at best.
Ciao, Dscho