2000

Grusel++ of the month

Home
Download Source
/******************************************************************************/
/*                                                                            */
/*                                                           FILE: AUGUST.CPP */
/*                                                                            */
/*  Have you ever seen these operators of the preprocessor ?                  */
/*  ========================================================                  */
/*                                                                            */
/*  Compiled and tested with Visual C++ V6.0                                  */
/*                                                                            */
/*  V1.00   31-AUG-2000   P. Tellenbach   http://www.heimetli.ch/             */
/*                                                                            */
/******************************************************************************/

#include <iostream>

using namespace std ;

#define String(s) #s

#define Concat(a,b) String(a ## b)

#define Main(a,b) \
   int main( int argc, char *argv[] ) { \
     cout << Concat(a,b) ; \
     return 0 ; \
   }

Main(Hello world,!)

Update 16. August 2020

The compiler complained that the concatenation operator produced an invalid preprocessor token. I solved this by simply removing the operator, because two adjacent strings are combined to a single one by the compiler.

/******************************************************************************/
/*                                                                            */
/*                                                           FILE: AUGUST.CPP */
/*                                                                            */
/*  Have you ever seen these operators of the preprocessor ?                  */
/*  ========================================================                  */
/*                                                                            */
/*  Compiled and tested with Visual C++ V6.0                                  */
/*                                                                            */
/*  V1.00   31-AUG-2000   P. Tellenbach   http://www.heimetli.ch/             */
/*                                                                            */
/*  Compiled and tested with g++ V8.3.0                                       */
/*                                                                            */
/*  V2.00   16-AUG-2020   P. Tellenbach   https://www.heimetli.ch/            */
/*                                                                            */
/******************************************************************************/

#include <iostream>

using namespace std ;

#define Concat(a,b) #a #b

#define Main(a,b) \
   int main( int argc, char *argv[] ) { \
     cout << Concat(a,b) ; \
     return 0 ; \
   }

Main(Hello world,!\n)