Advertisement

Macro help - Pasting a #

Started by October 03, 2000 03:53 AM
2 comments, last by Void 24 years, 3 months ago
Hi, Can anyone get a macro to be able to output a # character like so #define MacroName(exp) { #if .. } // { #if .. to be pasted
quote: Original post by Void
like so

#define MacroName(exp) { #if .. } // { #if .. to be pasted


It doesn''t make any sense.
Each preprocessor directive must be on the new line - and #define produce just one line.

By the way...

from MSDN:
"Preprocessor lines are recognized and carried out before macro expansion. Therefore, if a macro expands into something that looks like a preprocessor command, that command is not recognized by the preprocessor."
Advertisement
Preprocessor macros can be expanded to multiple lines, ex.

#define LIMIT(x, y) if(x > y) \
x = y; \
else if(x < -y) \
x = -y

But of course this is only for readabiliy by the user, the line could as well go

#define LIMIT(x, y) if(x > y) x = y; else if(x < -y) x = -y

Anyway, it would be great it something like this would be possible:

#define ENTER(x) #ifdef CURRENTFUNCTION \
#undef CURRENTFUNCTION \
#endif \
#define CURRENTFUNCTION "x"

#define LEAVE #ifdef CURRENTFUNCTION \
#undef CURRENTFUNCTION

#define ERROR(x) printf("%s(%i): %s - Error: %s", __FILE__, __LINE_, CURRENTFUNCTION, x)

Would be a shame if using preprocessor commands in macros wouldn''t be possible. I know it''s a lot of work to archive this by either implementing a very good preprocessor or creating a multi-pass one. Anyway, this should either be stated in the language commission papers.

-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
quote: Original post by Cygon

Preprocessor macros can be expanded to multiple lines, ex.

#define LIMIT(x, y) if(x > y) \
x = y; \
else if(x < -y) \
x = -y


Wrong.
Preprocessor macros always expand to a single line.
Lines containing preprocessor directives can be continued by immediately preceding the end-of-line marker with a backslash (\).
But of course this is only for readabiliy by the user...
(because actually it''s still just one line).

quote: Original post by Cygon

Would be a shame if using preprocessor commands in macros wouldn''t be possible. I know it''s a lot of work to archive this by either implementing a very good preprocessor or creating a multi-pass one.

And how it will know when to stop???

P.S.
Once I have compiled one file from the third-party code with macro expansion.
And I got a single-line functions (created by macros) with >30000 characters in the line.

This topic is closed to new replies.

Advertisement