why no error for multiple definition of a variable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-23 6:00 AM
hello dear forum
accidentally i define same global variable in two different c file
why I havent got any error
thank you
Labels:
- Labels:
-
STM32CubeIDE
This discussion is locked. Please start a new topic to ask your question.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-23 12:40 PM
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".
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-06-24 3:31 AM
An the linkers have different behaviour:
some allocates a variable for each source file, others only allocates one...
