Is long a data type or qualifier in C?

后端 未结 1 1265
无人及你
无人及你 2021-02-11 22:05

I am reading Programming in C by Stephan G. Kochan. He states that C has only five data types; int, float, double, char

1条回答
  •  死守一世寂寞
    2021-02-11 22:28

    He states that C has only five data types; int, float, double, char and _Bool.

    That's quite an over-simplification. Maybe intentional, if the book is aimed towards beginners.

    If you go through C11 6.2.5 it lists the following distinct data types:

    Character types (6.2.5/15)

    char
    signed char
    unsigned char
    

    Standard signed integer types (6.2.5/4)

    signed char
    short int
    int
    long int
    long long int
    

    Standard unsigned integer types (6.2.5/5)

    _Bool
    unsigned char
    unsigned short int
    unsigned int
    unsigned long int
    unsigned long long int
    

    Real floating types (6.2.5/10)

    float
    double
    long double
    

    Complex types (6.2.5/11)

    float _Complex
    double _Complex
    long double _Complex
    

    Enumerated type (6.2.5/16)

    enum {}
    

    void type (6.2.5/19) (void type is an incomplete type)

    void
    

    Derived types (6.2.5/20)

    • Array type
    • Structure type
    • Union type
    • Function type
    • Pointer type
    • Atomic type

    Formally the term is type specifier 6.7.2:

    type-specifier:
    void
    char
    short
    int
    long
    float
    double
    signed
    unsigned
    _Bool
    _Complex
    atomic-type-specifier
    struct-or-union-specifier
    enum-specifier
    typedef-name
    

    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.
    — void
    — char
    — signed char
    — unsigned char
    — short, signed short, short int, or signed short int
    — unsigned short, or unsigned short int
    — int, signed, or signed int
    — unsigned, or unsigned int
    — long, signed long, long int, or signed long int
    — unsigned long, or unsigned long int
    — long long, signed long long, long long int, or signed long long int
    — unsigned long long, or unsigned long long int
    — float
    — double
    — long double
    — _Bool
    — float _Complex
    — double _Complex
    — long double _Complex
    — atomic type specifier
    — struct or union specifier
    — enum specifier
    — typedef name

    As we can see, long is a type specifier. It is not a type qualifier.

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