[PATCH] support: Add TEST_COMPARE macro

Paul Eggert eggert@cs.ucla.edu
Fri Nov 24 18:31:00 GMT 2017


Florian Weimer wrote:
> I expect that GCC will eventually warn about such tautological comparisons.  The 
> current approach avoids such warnings.

I've found such warnings to be more trouble than they're worth, in cases like 
these. (Why would we want GCC to warn that it's doing an optimization? We *like* 
optimizations! :-) And efforts to suppress such warnings, such as using "x > 0" 
instead of "x < 0", typically cause the compiler to generate worse code.

If performance is not important here then I suppose it's OK. However, it's a bad 
habit and I don't want the habit to leak into code where performance matters.

>> I don't know what the context for this new macro is, and like Andreas I'm a 
>> bit puzzled as to its intended use.
> 
> The purpose is to check if two values are the same, and print them (and record a 
> test failure) if they are not.

Why would we want to compare (say) an uintptr_t value with a pid_t value? That 
sounds like a typo, and I'd rather see a compile-time diagnostic for the typo. 
It should be easy to arrange for such a diagnostic, and then we won't have to 
worry about run-time sign checking or pacifying GCC about comparisons.



More information about the Libc-alpha mailing list