What declarations of objects in C force storage to be stored (i.e. are definitions)?

C11 indicates in section 6.7 which declarations are also definitions:

The definition of an identifier is an announcement for this identifier that: - for an object, causes the storage to be reserved for this object;
[...]

I did not find an exhaustive list of statements about which object declarations are reserved. It is intuitive to me, but I could not get this information from the C11 standard.

+4
source share
1 answer

, , , . . int - (, const) .

  • , :

    int x = 1;
    
  • , :

    int x;
    auto int x;        // auto is the default anyways
    register int x;    // register is just a hint, but would be "storage" as well
    static int x;      // also reserves storage, but with static duration
    
  • ; :

    int x;
    static int x;
    

    (ยง6.9.2p2):

    , , static, . , , , 0

    , " ", .

  • extern :

    extern int x;     // <- not a definition
    

AFAIK, . , /, - .

+4

Source: https://habr.com/ru/post/1683748/


All Articles