Is it possible to redefine a c++ keyword using #define?
#ifdef int
#undef int
#define int 2
#endif
int main(){
//Do something with int
}
I
If you're don't use the standard libraries you're allowed to do so. In fact the preprocessor shouldn't distinguish between reserved and non-reserved words.
However that's probably not why you run into problems. First of all your examples don't do what you probably think. The fault is that int
is normally not a preprocessor defined macro. The #ifdef int
directive will therefore skip the following lines up to the terminating #endif
.
What this means is that your second example expands to:
// stuff from iostream and possibly other headers
int main(){
cout<
the fault is that cout<