If you use gcc and -Wall
the compiler already warns you
a.c:3:26: warning: operation on ‘b’ may be undefined [-Wsequence-point]
Whether to use such a construct is debatable from an performance point as well. When you look at
void swap1(int *a, int *b)
{
*a = (*a + *b) - (*b = *a);
}
void swap2(int *a, int *b)
{
int t = *a;
*a = *b;
*b = t;
}
and examine the assembly code
swap1:
.LFB0:
.cfi_startproc
movl (%rdi), %edx
movl (%rsi), %eax
movl %edx, (%rsi)
movl %eax, (%rdi)
ret
.cfi_endproc
swap2:
.LFB1:
.cfi_startproc
movl (%rdi), %eax
movl (%rsi), %edx
movl %edx, (%rdi)
movl %eax, (%rsi)
ret
.cfi_endproc
you can see no benefit for obfuscating the code.
Looking at C++ (g++) code, which does basically the same, but takes move
into account
#include <algorithm>
void swap3(int *a, int *b)
{
std::swap(*a, *b);
}
gives identical assembly output
_Z5swap3PiS_:
.LFB417:
.cfi_startproc
movl (%rdi), %eax
movl (%rsi), %edx
movl %edx, (%rdi)
movl %eax, (%rsi)
ret
.cfi_endproc
Taking gcc's warning into account and seeing no technical gain, I would say, stick with standard techniques. If this ever becomes a bottleneck, you can still investigate, how to improve or avoid this small piece of code.