It's completely consistent with those rules. Where do you see it disagreeing?
Did you mean "declared", or "defined" here? Please be consistent in your use of words, if you want to argue about their precise meanings and actions taken.
Well you can define a variable (memory is allocated) but its value can be unknown (undefined
) That’s the case for a non static local variable if you do not provide an initial value.
Declaring means to tell the compiler about its type and name.
@jremington, in the code you posted, this statement:
int x;
Both declares and defines the variable. However, it is not initialized. So, its value is undefined. "Define" has two different meanings here.
Everyone has to declare the variables they use.
Someone has to define it somewhere. The definition can also serves as a declaration.
Just read the thing @gfvalvo links in #7
a7
Ahh, as I suspected, nitpicking over the exact meanings of the words "declare" and "define" is, in this case, for the sake of argument!
Welcome to computer programming.
a7
Thanks, but I've been programming in various languages since the 1970s. The language wars can certainly be amusing at times.
Well me too but to be fair when I read this I also jumped
It seemed a C++ truth but the language does differentiate between declare and define, and it’s something important to grasp when you start working with multiple files and .h etc …
So I find it OK to be picky about this wording.
We are reacting the same way when newbies call a function a void… aren’t we? That’s part of being able to express oneself about the language and code…
No need to make this bigger than needs to be though… let’s stick to facts when we can…no alternate truth ![]()
Good attitude, if you can agree on some facts. To quote @gfvalvo
"Define" has two different meanings here.
Yes
The variable is defined
The content of the variable is undefined
(The point was more that declaring does not allocate memory)
X-actly. I like the new one I saw here today somewhere, void.setup and void.loop… very creative nomenclaturing.
a7
Every day someone invents a new language on here, a fun place to be
Exactly what I was saying. And it's not nit picking, the difference is critical.
A variable can be declared any number of times. But, it must be defined exactly once.
Whether or not the variable's value is defined is a different question.
fixed that for you
My statement was correct. A local variable that is not initialized will have an undefined value.
Note, it does not say redefinition, it says re-declaration Oy9Jvw - Online C++0x Compiler & Debugging Tool - Ideone.com and is an error
First mention of redefinition here - have I missed something?
I hope not
extern int myInt;
extern int myInt;
extern int myInt;