Timeline for Why C allows multiple global declarations of the same variable but NOT multiple local declarations?
Current License: CC BY-SA 3.0
15 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 26, 2017 at 6:30 | audit | Suggested edits | |||
| Oct 26, 2017 at 6:34 | |||||
| Oct 25, 2017 at 11:46 | comment | added | shawnhcorey |
You cannot declare a local variable even once. All you can do is define it. Declaring a variable is telling the compiler what it is. Defining a variable is telling the compiler to allocate memory for it. You must define all variables. In C, a definition of a global variable can be used for a declaration multiple times. But if the program only has extern int x;, which is a declaration, the compile will abort since there is no place where memory is allocated to the variable.
|
|
| Oct 6, 2017 at 8:35 | history | tweeted | twitter.com/StackSoftEng/status/916220233127485440 | ||
| Oct 5, 2017 at 13:07 | history | reopened |
Doc Brown JacquesB Thomas Owens♦ |
||
| Oct 4, 2017 at 21:54 | review | Reopen votes | |||
| Oct 5, 2017 at 13:09 | |||||
| Oct 4, 2017 at 21:42 | history | edited | Doc Brown | CC BY-SA 3.0 |
added some explanations for the hastily closers
|
| S Oct 4, 2017 at 17:48 | history | unlocked | CommunityBot | ||
| S Oct 4, 2017 at 17:48 | history | locked | CommunityBot | ||
| S Oct 4, 2017 at 17:48 | history | closed |
gnat amon Greg Burghardt Bart van Ingen Schenau 8bittree |
Not suitable for this site | |
| Oct 4, 2017 at 17:41 | answer | added | Erik Eidt | timeline score: 14 | |
| Oct 4, 2017 at 14:48 | comment | added | yoyo_fun | @Walfrat Yes the variable is always declared of the same type. If two variables of the same name but with different type are declared globally the the gcc outputs error "conflicting types for a (variable)" | |
| Oct 4, 2017 at 14:40 | comment | added | Walfrat | Just to be sure, your global variable, had always the same type right ? | |
| Oct 4, 2017 at 11:46 | review | Close votes | |||
| Oct 4, 2017 at 17:48 | |||||
| Oct 4, 2017 at 10:41 | answer | added | msc | timeline score: 11 | |
| Oct 4, 2017 at 10:36 | history | asked | yoyo_fun | CC BY-SA 3.0 |