Message-ID: <8D53104ECD0CD211AF4000A0C9D60AE30146182F@probe-2.acclaim-euro.net> From: Shawn Hargreaves To: djgpp AT delorie DOT com Subject: Re: Allegro: How to wrap "..." argumentlist Date: Tue, 22 Jun 1999 11:32:07 +0100 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1460.8) Content-Type: text/plain Reply-To: djgpp AT delorie DOT com A. Jans-Beken writes: >This works all fine. But now I want to wrap this function... > > textprintf(BITMAP *bmp, FONT *f, int x, y, color, char *fmt, ...); > >I do not understand how to do this. The C++ primer that I have (old >edition) is inconclusive. A gues would be: > > void textprintf(int x, y, color, char *fmt, ... ) { > ::textprintf(bob, font, x, y, color, fmt, ... ); > } > > But the compiler doesn't like this at all. Standard C doesn't provide any way to do this. If you think about it a bit, the reasons should be obvious. This function has been passed an unknown number of parameters on the stack, and the only way for it to find out how many and what type of parameters these are, is for it to parse the fmt string and understand the tokens within it. Now you want to pass a copy of these arguments on to a new function, which requires creating a new argument block on the stack, but how can the compiler know how much data to copy? At this point, it knows nothing about the details of printf-style format specifiers, which is the only way to find that information. If you understand the layout of parameters on the stack, you could use some inline asm to fake your call to the Allegro routine into using the exact same parameters as you were called with (you'd need to remove your stack frame, and then jump directly to the Allegro function). This is very non-portable, though, and prone to error if you aren't very careful about how the compiler can optimise around your asm fragment. Alternatively, there is a gcc extension that can help with this situation: see info "c extensions" "constructing calls". I'm not sure if this will work with a C++ method, though. Shawn Hargreaves.