Why is creating a variable using 'extern' a declaration and not a definition?

后端 未结 5 1238
-上瘾入骨i
-上瘾入骨i 2021-01-21 22:42

I came across the following problem while reading ...just cant get the logic behind this.

auto int c;
static int c;
register int c;
extern int c;
5条回答
  •  情歌与酒
    2021-01-21 22:53

    The first 3 statements actually allocate a place for the int.

    The last one does not. All it does it tell the compiler is that somewhere in another compilation unit, an int called c will be defined.

    If it is not defined, you'll get a linker error later on. Unsurprisingly enough, the linker will say that c is not defined.

提交回复
热议问题