This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] Use 1U everywhere in elf/elf.h.
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Petr Machata <pmachata at redhat dot com>
- Cc: Carlos O'Donell <carlos at redhat dot com>, Roland McGrath <roland at hack dot frob dot com>, GNU C Library <libc-alpha at sourceware dot org>, Andreas Schwab <schwab at linux-m68k dot org>
- Date: Wed, 25 Mar 2015 15:04:22 +0000
- Subject: Re: [PATCH] Use 1U everywhere in elf/elf.h.
- Authentication-results: sourceware.org; auth=none
- References: <54F9E0CE dot 8070303 at redhat dot com> <20150306180147 dot 7EA492C3B32 at topped-with-meat dot com> <54FA28D8 dot 1080209 at redhat dot com> <20150306222818 dot 643092C3B39 at topped-with-meat dot com> <54FB4511 dot 2020008 at redhat dot com> <87d23ynm4r dot fsf at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1503242114280 dot 16467 at digraph dot polyomino dot org dot uk> <87iodpmcfr dot fsf at redhat dot com>
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