On Mon, 8 Dec 1997, Akuma/Chris Baggett/DOOMer wrote: > ok, in my process of moving to C++, > i created a printf() member function in class/struct char_data > char_data::printf() > which is just like printf. > so I can do > ch->printf("string %s %d", anotherstring, aninteger); > well, what i've done > with the > ch->print() was use > send_to_char() as a macro like so > > #define send_to_char(messg, ch) (ch)->print(messg) > > I was wondering if it was possible to do that with send_to_charf > ie > #define send_to_charf(ch, messg) (ch)->printf(messg) > and possibly it would accept messg as all the excess pointers and stuff > > send_to_charf(ch, "messg %s %d %d", string, number, number); > would be changed in the preprocessor to > ch->printf("messg %s %d %d", string, number, number); > > is this possible? this is just to save > my future coders trouble in trying to understand what i've > done to CircleMUD. If you are going to use C++, use C++ ! Hiding what you've done using macros is a terrible idea. Get out perl, and subtitute all ocurrance of send_to_char with ch->print. This is not too hard with some regular expression :) Anyway, there are two ways if you absolutely want to do this. 1 - somewhat harder. #define the macro as: #define send_to_charf(ch,args) (ch)->printf args You will have to call this as: send_to_charf(ch, ("Hello, I must be %s", s)); Note the extra parens around the extra args! 2 - gcc extension of variable arguments in a macro: #define send_to_charf(ch, format, args...) (ch)->printf(format, ##args) This is described in "info gcc". ============================================================================= Erwin Andreasen Herlev, Denmark <erwin@pip.dknet.dk> UNIX System Programmer <URL:http://www.abandoned.org/drylock/> <*> (not speaking for) DDE ============================================================================= +------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST