c - Should definition and declaration match? -


in .h file have

extern int a[4]; 

in .c file have

int a[10]; 

so there issues this?

declaration , definition size matters? not right?

if write sizeof(a) in 1 of files, output? undefined behavior?

if include header file in source file 2 declarations of a must have same type c says:

(c11, 6.7p4) "all declarations in same scope refer same object or function shall specify compatible types."

even if 2 declarations in 2 translation units, need have same type:

(c11, 6.2.7p2) "all declarations refer same object or function shall have compatible type; otherwise, behavior undefined."


Comments