This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: __typeof__ (const int)
- From: Liu Hao <lh_mouse at 126 dot com>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>, Aurelien Buhrig <aurelien dot buhrig dot gcc at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Thu, 16 Feb 2017 22:33:35 +0800
- Subject: Re: __typeof__ (const int)
- Authentication-results: sourceware.org; auth=none
- References: <134c9ad3-9f94-1cca-2bd0-bc1dc1d8c9c8@gmail.com> <CAH6eHdS2oh5ZMQjvgtJzhN6XYNGmrYVB=1y6Zv-Mo5q6p-03uw@mail.gmail.com>
On 2017/2/16 21:39, Jonathan Wakely wrote:
On a private target (using newlib-stdint.h), sizeof(__typeof__ (-32768))
returns 4 but sizeof(__typeof__ (-32767)) returns 2...
This has nothing to do with __typeof__ only to do with the rules of C
that determine the type of an integer constant, see
http://en.cppreference.com/w/c/language/integer_constant#The_type_of_the_integer_constant
Presumably your private port has a 16-bit int, so -32768 doesn't fit
in int and has a 32-bit type instead. If that's not the case then you
have a bug in the port and it's selecting the wrong type for the
integer constant -32767.
It is 32768 that does not fit in `int`. There is no negative integer
constant. -32768 is a unary minus operator followed by an integer
constant 32768, which has type `long` if it does not fit in `int`.
--
Best regards,
LH_Mouse