[PATCH] support: Add TEST_COMPARE macro

Paul Eggert eggert@cs.ucla.edu
Sat Nov 25 00:05:00 GMT 2017


Florian Weimer wrote:
> comparisons between actual and 
> expected values often have differing types.  Concrete types vary between 
> architectures, and not just their sizes (e.g., 32-bit architectures use longs 
> where 64-bit architectures use int).

Yes, but I'm still not seeing the motivation for doing this via a run-time test 
rather than a compile-time test. Can you show an example or two of problems that 
the signedness part of this macro will fix?

Also, why can't we rely on -Wsign-compare to warn about these problems?

As for what I have in mind for a compile-time test, please see the attached 
code. This also checks for floating-point types, and it avoids a false alarm in 
some cases when a narrower-than-int unsigned type is promoted (that's what the 
"+ (a)" and "+ (b)" are for). Finally, it suppresses -Wtype-limits since those 
GCC warnings are counterproductive in this kind of code.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-compare.c
Type: text/x-csrc
Size: 2205 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20171125/47d2fde7/attachment.bin>


More information about the Libc-alpha mailing list