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; /*
lets understand same stuff by program
test.c
#include
#include"head.h"
struct token id_tokens[10];
int main()
{
printf("In original file: %p",id_tokens);
testing();
}
head.h
struct token {
int temp;
};
test1.c with v1
#include
#include"head.h"
extern struct token* id_tokens;
void testing () {
printf("In other file %p",id_tokens);
}
Output : In original file: 0x601040In other file (nil)
test1.c with v2
#include
#include"head.h"
extern struct token id_tokens[];
void testing () {
printf("In other file %p",id_tokens);
}
Output : In original file: 0x601040In other file 0x601040
This clearly shows that v1 is not correct and v2 is correct.