Archived

This topic is now archived and is closed to further replies.

Void

Macro help - Pasting a #

Recommended Posts

Void    126
Hi, Can anyone get a macro to be able to output a # character like so #define MacroName(exp) { #if .. } // { #if .. to be pasted

Share this post


Link to post
Share on other sites
Serge K    154
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."

Share this post


Link to post
Share on other sites
Cygon    1219
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-

Share this post


Link to post
Share on other sites
Serge K    154
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.

Share this post


Link to post
Share on other sites