Is there a way to use a keyword as a variable name? Well, you will answer who cares about the name, but I am just wondering....
Is there a way to use a keyword as a variable name? Well, you will answer who cares about the name, but I am just wondering....
In C++, keywords are reserved words that may not be used in any other context. On the other hand, names and keywords are case sensitive...
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
While laserlight is kind enough to point out that keywords are case sensitive, I think its a dubious practice to be writing code that untilizes that fact unless....
Example:
I guess it all depends on what you are trying to do.Code:class Int { // write a class that works generally like an int, but has some nifty member functions as well };
No.
Macros can be key words, so you can make it look like a keyword is a variable, by making it a macro to some other name. DO NOT DO THIS.
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.
That is true, since semantic analysis only happens after macro expansion. On the other hand, the program that results from macro expansion does not contain a keyword as a variable name, so the unqualified "no" is misleading, since it is still true that keywords are reserved words that may not be used in any other context.Macros can be key words, so you can make it look like a keyword is a variable, by making it a macro to some other name.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Example:
Behold! Ok... that isn't exactly an impressive usage of what King is talking about. The one interesting and useful aspect of doing this is when you are trying to default something to signed or unsigned.Code:typedef int whatever; #define int whatever
Example:
But even that is no substitute for a decent makefile since doing something similar to the above example will result in problems when you try to later use a signed int.Code:typedef unsigned int uint; #define int uint