This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: __typeof__ (const int)


On 2017-02-16 22:54 +0800, Xi Ruoyao wrote:

> According to the Standard, '32768' is a decimal literal, but '-32768'
> is not. It's an expression using unary '-' to the literal '32768'.
> Here '32768' has type int32_t. So the expression also has type
> int32_t despite the result can fit into an int16_t.

It's called 'literal' in C++ Standard. In C Standard it's just called
integer constant.

For example, in C99 6.4.4.1 the grammar of decimal-constant is:

    decimal-constant:
        nonzero-digit
        decimal-constant digit

We can see a decimal constant must begin with a nonzero-digit,
'-' is not a nonzero-digit. So '-32768' is not a decimal-constant.

The description of 6.4.4.1 also said:

    An integer constant begins with a digit.
-- 
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University


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