About Tentative definition

前端 未结 2 1101
青春惊慌失措
青春惊慌失措 2020-11-22 08:41

I read from a book about tentative defination that,

A tentative definition is any external data declaration that has no storage class specifier and

2条回答
  •  广开言路
    2020-11-22 09:17

    The first works because both your definitions of a are tentative, which can be duplicated as often as you see fit. At the end of the translation unit, no non-tentative definition has been seen, so what you've specified for attributes is combined with defaults to give a final definition of a, so it'll have external linkage, static storage duration, and be initialized to 0.

    The problem with the second has nothing to do with tentative definitions. Your printf("Hi"); needs to be inside a function to work -- it's not a declaration or a definition (tentative or otherwise); it's just not allowed there.

提交回复
热议问题