Forum : ST7/STM8
Original Post
Post Information | Post |
---|---|
January 18, 2010 - 8:24pm
|
char var1; Is this behavior intentional? |
Forum : ST7/STM8
Post Information | Post |
---|---|
January 18, 2010 - 8:24pm
|
char var1; Is this behavior intentional? |
Hi Jacob,
Thanks for your remark.
In C, you can declare a variable several times, if the identifier has some linkage.
This means that if "char var1" is a global variable, you can declare it several times -- but not if it is a local variable.
So:
Is perfectly legal C. (I am surprised about your "The compiler flags this" comment. I verified that our compiler does NOT flag it).
However, it is allowed only for declarations, not for definitions.
And also, you cannot have several declarations for local variables in a function.
So in brief, the code you submitted is perfectly legal C (excepted that the "bit" type is an extension to the standard), and the compiler has the appropriate behavior.
Let us know if you have an issue with this.
Regards,
Bruno
Thanks for that information; I did not realize that was legal syntax. Reviewing my actual code, I found that I'd made a typographical error, so as you suggested, they did not have the same linkage.