I saw a complete list of C keywords and I didn't know what auto did or some other keywords did.
The ones I can remember that I've never understood fully were :
Edit : The last one I didn't know was volatile.Code:register auto ...
I saw a complete list of C keywords and I didn't know what auto did or some other keywords did.
The ones I can remember that I've never understood fully were :
Edit : The last one I didn't know was volatile.Code:register auto ...
Last edited by HelpfulPerson; 07-21-2013 at 01:46 PM.
register is a request for the compiler to keep that variable available on the (much faster) registers, internally. Pretty much not used anymore, because the compilers are smarter than in decades past. The compiler is free to set up the variables, as it wishes, in any case.
auto is the normal (default) variable, we just don't use it. Inside any function, "int i" for instance, is an auto variable, and has limited scope. Contrasts with static variables, which have an extended scope.
volatile warns the compiler that this variable can have NO assumptions made - typically because another sensor or program, will be changing it, in addition to the current function. Basically, it forces the compiler to re-check it's most current value, before it works with it, even though the function did not change it, since the last time it was given a value.
Auto, register, static, and extern are the four storage classes that C variables can have, with auto being the default. So most variables are implicitly auto. register variables behave just like auto variabes. Register serves as a hint to the compiler to put a variable in a register instead of on the stack. Most modern compilers treat auto and register variables identically.
In C++11 auto has a different meaning.
Volitile is a qualifier that works identially to const. It is used for values that may be modified externally to your program. Unlike in Java, it is not sufficent for multithreaded access.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Huh? Volatile and const are quite different. In fact, almost the opposite.Volitile is a qualifier that works identially to const. It is used for values that may be modified externally to your program. Unlike in Java, it is not sufficent for multithreaded access.
I think King Mir is referring to its use from a syntax point of view.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
@Adak: Scope applies to identifiers and storage duration applies to objects. An example:
'x' would have block scope (and no linkage), and the object associated with 'x' would have static storage duration.Code:void f() { static int x; }
x is local, so it has no linkage. You're probably thinking of static variables at file scope.Originally Posted by oogabooga
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
The "region of data storage in the execution environment" that is associated with the variable named x, the contents of which represents a value as determined by the type of x.Originally Posted by Adak
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks for the definition, grumpy and laserlight.