You cannot get close to a == b == c .
To call experienced C programmers the least unexpected, I think this is the best
if(a == b && b == c && c == d && d == e && e == f)
i.e. basically like what you already have, with smaller brackets. I donβt always mind adding parentheses that have nothing to do with the compiler to help people who donβt know all the priority rules, but I think comparisons separated by the && character (without || ) are simple enough that the brackets were more messy than they cost.
If the variable names are long, then all this on one line will not be beautiful, therefore, perhaps
if(a == b && b == c && c == d && d == e && e == f)
or it might be better, since duplicating a in each line will be immediately noticeable:
if(a == b && a == c && a == d && a == e && a == f)
If you really want it to be compact,
The p99 preprocessor offers the following:
#include "p99_for.h" if(P99_ARE_EQ(a,b,c,d,e,f))
which looks like John Zwink's answer, but does not require an auxiliary function.
Wumpus Q. Wumbley
source share