This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Use 1U everywhere in elf/elf.h.

On Wed, 25 Mar 2015, Petr Machata wrote:

> > If a 32-bit signed type were correct, then it would be correct to have
> > ((int) 0x80000000) (a negative value) as the value of this macro.  I
> > don't see testing whether things fit in a certain number of bits as
> > making sense.  It makes more sense to test the types of the macros, if
> > we first establish what the correct type is.
> Would a test like this make more sense to you?
> #define TEST_FITS(VALUE, NAME, TYPE, W)					\
>   _Static_assert ((TYPE) (VALUE) == VALUE /*...*/);

You mean to apply this to both Elf32_Word and Elf64_Xword, in the 
sh_flags case, for example?

I think the difficulty is the C rules for implicit type conversions; a 
comparison (uint64_t) -1 == -1 would evaluate to true, for example.  If 
you want to compare values of arbitrary integer types, as a plain integer 
comparison, you need to compare the signs of the two values, ((TYPE) 
(VALUE) < 0) == ((VALUE) < 0), as well as the plain == comparison.

Joseph S. Myers

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]