Tuesday, 27 August 2013

Preprocess to define '#define'

Preprocess to define '#define'

I've been looking through code golf and got an idea to try this code:
#define D #define after adding this line, everything worked fine, however
I expanded it into this:
#define D #define
D VALUE
And here I got 5 compilation error. If I change D into #define everything
is fine, can someone explain, why this code is illegal?
NOTE: I used VS2008 compiler.
EDIT: After some answers I see that I needed to give compilations error list:
error C2121: '#' : invalid character : possibly the result of a macro
expansion
error C2146: syntax error : missing ';' before identifier 'VALUE'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
error C2144: syntax error : 'void' should be preceded by ';'
error C4430: missing type specifier - int assumed. Note: C++ does not
support default-int
First error shows that D is not just define but also includes #.

No comments:

Post a Comment