Skip to main content
mehmet.karakaya
Associate III
June 23, 2021
Question

why no error for multiple definition of a variable

hello dear forum

accidentally i define same global variable in two different c file

why I havent got any error

thank you

This topic has been closed for replies.

2 replies

TDK
June 23, 2021

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
June 24, 2021

An the linkers have different behaviour:

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