Hello everyone,
I have searched and found the term automatic variable means function local variable, compared with static and global variable. Is that correct?
thanks in advance,
George
Hello everyone,
I have searched and found the term automatic variable means function local variable, compared with static and global variable. Is that correct?
thanks in advance,
George
Yes, that's what it means.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
It means a variable that will be destroyed as soon as it goes out of scope (i.e. not a pointer, since you manually have to free() them)
I think I've also seen an auto keyword, although I don't see why you would ever need to use it since it's auto by default?
Yes, auto is a keyword in C. It doesn't provide much usefullness tho'. In Bjarne's book, it says "If you absolutely must be explicit about this, C++ provides the redundant keyword auto" [This is the ONLY reference to auto anywhere in the book].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I, for one, am glad for the presence of the auto keyword. There are rumblings afoot that this keyword will be co-opted to a new use in the new C++ standard. It will mean "whatever type makes this declaration valid." Should prove extremely useful for metaprogramming.
Example
Where the type of boost::some_crazy_object() might be some enormous 5000-character long template typename, which you neither care to infer nor could even if you wanted to. "auto" in this case means "that type," so you can easily declare x without having to figure out what exact type is being used.Code:auto x = boost::some_crazy_object();
Also, I hope they allow it for return types from template functions (allowing it for normal functions would be unreasonable and probably impossible to implement):
Where the return type is whatever type some_crazy_thing(blah) is.Code:template <typename T> auto my_func(T blah) { return some_crazy_thing(blah); }
Can't wait!
It would break backwards compatibility with existing C and C++ programs that actually use the auto keyword. I don't know if this is better than introducing a new keyword or not, because a new keyword could have been used for a variable name in existing code.
Or the new keyword could be named something like _Bool. But that is hard to type and so they introduced a new header for bool, an easier name to swallow.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
>> There are rumblings afoot that this keyword will be co-opted to a new use in the new C++ standard.
off-topic, but in addition to this I believe a typeof keyword is being considered as well, eg:
or was I just daydreaming?Code:typedef typeof(insane_template_instantiation) type;
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Apparently not. http://www.boost.org/doc/html/typeof.html
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.