extern declaration, T* v/s T[]

后端 未结 3 956
一向
一向 2020-12-15 00:56

I saw following piece of code in a legacy project.

/* token.c */
struct token id_tokens[MAX_TOKENS];

/* analyse.c (v1) */
extern struct token *id_tokens; /*         


        
3条回答
  •  醉话见心
    2020-12-15 01:49

    The first version is wrong. Arrays are NOT pointers, the declaration extern struct token *id_tokens; doesn't match the definition type struct token id_tokens[MAX_TOKENS];.

    Reference: C FAQ: I had the definition char a[6] in one source file, and in another I declared extern char *a. Why didn't it work?. Also, see this.

提交回复
热议问题