Sender: crough45 AT amc DOT de Message-Id: <97Aug6.163553gmt+0100.17055@internet01.amc.de> Date: Wed, 6 Aug 1997 15:38:40 +0100 From: Chris Croughton Mime-Version: 1.0 To: max AT alcyone DOT com Cc: djgpp AT delorie DOT com Subject: Re: '...' handling (with djgpp, although likely ubiquitous)... Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Erik Max Francis wrote: > You don't have set it to anything. Declaring a > va_list auto variable indicates that you're > intercepting the arguments to the function (it > hooks into the stack) and works from there. It > should be the first declared variable, incidentally. That is dangerously incorrect. Declaring a variable with va_list does nothing to "hook into" the stack at all, it's just a variable (often with type void*, depending on the compiler, but it can be more complex). You do have to point it at the first variable argument. That's what doing va_start(argc, format); does, it points the variable at the stack frame. You also must put va_end(args); in the same scope. The variable must also not be accessed too much within that scope - you can use va_arg(args, type) to get at each argument in turn, or you can pass it to another function (like vprintf), but mixing the two is likely to have odd results (or at least nonportable ones). However, it can be reset. You can say, for instance, va_start(args, format); vprintf(format, args); va_end(args); va_start(args, format); vfprintf(stderr, format, args); va_end(args); to print the same thing to both stdout and stderr, but you must have the va_end and va_start between them. There is no need for it to be the first declared variable, either, it is just an ordinary variable... Chris C