Search code examples
c-preprocessorstringification

Why pre-processor gives a space?


I want to comment a line using the pre-processor:

#define open /##*

#define close */

main()
{
        open commented line close
}

when I do $gcc -E filename.c I expected

/* commented line */ 

but I got

/ * commented line */ 

so that the compiler shows an error

Why it is giving an unwanted space ?


Solution

  • The preprocessor runs and produces code in a form that the C compiler can understand. It only processes your code once, so even if you could produce a /* with your #define, the compiler would see the /* and give you an error because it's not valid C code (it's a preprocessing instruction).

    This doesn't seem like a very good thing to do.