Skip to main content
gamedev.net
🔒 Locked

Complex Macros

Started by Thunder_Hawk Mar 16, 2003 at 5:40 PM 7 replies 400+ views
Original Post
Thunder_Hawk
Thunder_Hawk

  
#define MAKENEW(x) #define x SOMETHING_ELSE
  
Is there any way to accomplish what I''m trying to do here? ______________________________ And the Phoenix shall rise from the ashes... --Thunder_Hawk -- ¦þ ______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
Fruny
Fruny
No.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Sneftel
Sneftel
Nope.


How appropriate. You fight like a cow.
Thunder_Hawk
Thunder_Hawk
You mean there isn''t any way to escape a # sign in a macro?
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
Fruny
Fruny
Macros cannot contain other preprocessor directives ( beside the ''stringizing'' # and the ''token pasting'' ## ).


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thunder_Hawk
Thunder_Hawk
Interesting...back to the drawing board I guess
BTW, this is nothing important I''m just kind of tossing around ideas on things I might do, and this seemed like something neat to try out.
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
NickB
NickB
on presumption that you wanted to transform x before it got to the first #define, why not just transform it in the define ?
hewhay
hewhay
I think that you are trying to declare variables using names dependant on runtime data (??). If it so, i guess that a dictionary implementation (maybe a hash table if you are interested on performance and not memory) would be a better solution. Also defines work at compile time so if your syntax weren''t incorrect it would have been the same to use #define y SOMETHING_ELSE and MAKENEW (y)
humanity will always be slaved by its ignorance
Fruny
Fruny
quote:
Original post by hewhay
Also defines work at compile time so if your syntax weren''t incorrect it would have been the same to use #define y SOMETHING_ELSE and MAKENEW (y)


Actually, #define operate before compile-time. That''s why they are called preprocessor macros, and why they let you do things without any language checking. That''s also why preprocessor macros do not respect scope, types ...


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.