Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you're wanting to do is to simulate the call stack so you can pass a constructed va_list to foo(). This is rather specific to the compiler ( and warning, there are differences between even 32- and 64-bit compilers ). The following code is for <strong><em>ENTERTAINMENT PURPOSES ONLY!!!</em></strong> as (if it even works on your system) it is prone to breakage. With it, I use a flat memory buffer and the populate it with a count and a bunch of character strings. You could fill it as appropriate with pointers to your strings and hand them down.</p> <p>It does seem to work on my system, Windows 7 w/ Visual Studio 2008, for 32-bit applications only.</p> <p><strong>* BAD IDEA CODE FOLLOWS!!! *</strong></p> <pre><code>#define PSEUDOSTACKSIZE ( sizeof(int) + 999 * sizeof(const char*) ) #pragma pack( push,1 ) union PSEUDOSTACK { int count; char data[PSEUDOSTACKSIZE]; }; #pragma pack( pop ) void foo( int count, va_list args ) { for ( int i = 0; i &lt; count; i++ ) { char *s = va_arg( args, char* ); printf( "%s\n", s); } } void bar( PSEUDOSTACK data, ... ) { va_list args; va_start(args, data.count); foo( data.count, args); va_end(args); } // And later on, the actual test case code. PSEUDOSTACK barData; barData.count = 999; char *p = barData.data + sizeof(int); for ( int i = 0; i &lt; 999; i++, p += sizeof(char*) ) { *reinterpret_cast&lt;char**&gt;(p) = "ThisIsABadIdea"; } bar( barData ); </code></pre> <p>I'll now go hang my head in shame for thinking of such an idea.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload