www.digitalmars.com         C & C++   DMDScript  

c++ - Couple of postings at comp.lang.C++ Re ##, food for thought

I'd think...

     #defina a(x) x

should result in 


But then I'm not sure what the compiler should do if I write,

     a(the_file)ext  //no dot  

Rob Williscroft wrote: It should produce the output "the_fileext" (not the quotes), however this is 2 preproesor tokens (though only one C++ identifier). Add: #define the_fileext Expansion #define B() a(the_file) B() should produce: "the_fileext" Not "Expansion". I.e. juxtaposition is fine for producing C++ tokens but not for preprocessor tokens (i.e. tokens that can themselves be expanded). The pre ## way was something like: #define cat(a, b ) a/**/b #define XY Expanded cat(X, Y) produced "Expanded". This is what (IMO) ## was designed to fix.
Wow!  My head is spinning. Ok, you're saying that in the old days a
macro could modify the instance of another macro before the latter was
applied.  But I thought that was the way it is currently, isn't it?
Would your last example NOT do that now?  And how does ## prevent...
what exactly?
Maybe if you could give me a 4-way example: What worked and didn't
work / then and now.  Thx.

Rob Williscroft wrote: The problem with this method is when the C standard came out it required comments to be replaced with a single space character. Presumably this was so you couldn't write print/* whatever */f( "\n" ); and have the compiler see printf( "\n" ); So code that relied on this behaviour needed another way of achiving the same thing hence the invention of ##. Rob.
Dec 03 2003