Is long long a type in C?

前端 未结 1 2125
我在风中等你
我在风中等你 2021-02-18 22:38

I know the title seems quite stupid, but I think it\'s worth asking.

Take this declaration(or definition, maybe) for example:

_Thread_local long volatile         


        
相关标签:
1条回答
  • 2021-02-18 23:02

    If you read the right bits of the standard carefully enough, you find that the monster declaration in the question is valid, even if implausible.

    The 'right bits' includes:

    6.2.5 Types

    There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int. (These and other types may be designated in several additional ways, as described in 6.7.2.)

    For each of the signed integer types, there is a corresponding (but different) unsigned integer type (designated with the keyword unsigned) that uses the same amount of storage (including sign information) and has the same alignment requirements.

    6.7.2 Type specifiers

    At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.

    • long long, signed long long, long long int, or signed long long int
    • unsigned long long, or unsigned long long int

    Other declaration specifiers include storage classes (static and _Thread_local in the example), and type qualifiers (volatile and _Atomic).

    6.7 Declarations

    6.7 Declarations

    Syntax

    declaration:
         declaration-specifiers init-declarator-listopt ;
         static_assert-declaration

    declaration-specifiers:
         storage-class-specifier
         declaration-specifiersopt
         type-specifier declaration-specifiersopt
         type-qualifier declaration-specifiersopt
         function-specifier declaration-specifiersopt
         alignment-specifier declaration-specifiersopt

    Also, as noted by Olaf in a comment:

    6.11.5 Storage-class specifiers

    The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.

    It is also eccentric to split up the integer type keywords (the type specifier). A more orthodox version of the declaration would be:

    static _Thread_local _Atomic const volatile unsigned long long int x = 10;
    

    (or it might drop the int).

    0 讨论(0)
提交回复
热议问题