long long 是 C 中的一种类型吗?

Is long long a type in C?

我知道这个标题看起来很愚蠢,但我认为值得一问。

以这个声明(或定义,也许)为例:

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

我以前把long long看成一个类型,但是如果是类型名,怎么能往里面塞那么多限定词呢?

所以我带着这个问题咨询了N1570,结果更加糊涂了。它提到了一些术语,例如“type-specifier”和“type-qualifier”,我找不到[= "type specifiers" 中的 11=],但 long long 不是 C 中的原始类型吗?有很多书告诉我!


澄清不重复:

是的,我看到an existing question处理long int long,但是这个问题与限定符有关,并且在C.

如果您足够仔细地阅读标准的正确部分,您会发现问题中的怪物声明是有效的,即使难以置信。

'right bits'包括:

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

其他声明说明符包括存储 类(示例中的 static_Thread_local)和类型限定符(volatile_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

此外,正如 Olaf in a 所述:

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.

把整型关键字(类型说明符)拆分开来也很古怪。声明的更正统版本是:

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

(或者它可能会删除 int)。