Ugly macros question for fun

Since it is first time when I saw this expression I decided to post it here:

	#define GET_STRING(data) #data
	const char* pStr = GET_STRING(4);


at runtime the pStr variable will be set to “4″.

However, preprocessor will be executed before the compiler so in the case of this expression:

	int i=6;
	const char* pStr = GET_STRING( i );

The value os pStr will be set to “i”.

This behavior is stardard and it worked on VC 7.1, gcc 3.2.3.

There is really nice way to test a piece of code without even having a local compiler on your machine.
The Comeau C/C++ Online allows you to compile a C/C++ code.
All you have to do is to paste a code into the web page form. Since there is only a compiler without a linker this idea
helps to identify possible standard compliance problems in your C/C++ code.

Leave a Reply