cancel
Showing results for 
Search instead for 
Did you mean: 

why no error for multiple definition of a variable

mehmet.karakaya
Associate III

hello dear forum

accidentally i define same global variable in two different c file

why I havent got any error

thank you

2 REPLIES 2
TDK
Guru

C files are their own compilation unit. Other C files cannot see variables in them unless they are defined in a header (as extern, in this case).

Edit: above only applies if they're declared static.

If you feel a post has answered your question, please click "Accept as Solution".
Nikita91
Lead II

An the linkers have different behaviour:

some allocates a variable for each source file, others only allocates one...