Message-ID: <3EA395F3.78C4A4D4@acm.org> From: Eric Sosman X-Mailer: Mozilla 4.72 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: __builtin_va_list bug? References: <0ab801c306bf$4dacb430$0600000a AT broadpark DOT no> <3EA26C19 DOT 81D82449 AT acm DOT org> <0c2401c30751$05203c90$0600000a AT broadpark DOT no> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 44 Date: Mon, 21 Apr 2003 11:55:21 GMT NNTP-Posting-Host: 12.91.11.16 X-Complaints-To: abuse AT worldnet DOT att DOT net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1050926121 12.91.11.16 (Mon, 21 Apr 2003 11:55:21 GMT) NNTP-Posting-Date: Mon, 21 Apr 2003 11:55:21 GMT Organization: AT&T Worldnet To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Gisle Vanem wrote: > > "Eric Sosman" said: > > > > #include > > > char x; > > > void foo (va_list arg) > > > > Hold on; stop right there. You've included , but you're > > using the argument list declaration from the pre-Standard > > (or with some compilers). The two are not the same, they > > are not interchangeable, and they are *definitely* not miscible. > > You mean using "va_list" is pre-standard? (it's used in ) > That's funny since djgpp uses it all the time. Have a look at e.g. > src\libc\ansi\stdio\doprnt.c. My apologies; Richard Dawe pointed out my error. uses some of the same names as the pre-Standard , and I mis-read the usage you quoted. > > > x = va_arg (arg, char); > > > > This will be wrong with either or , since > > the actual type of the parameter is not `char' but whatever `char' > > gets promoted to: `int' on most machines, but perhaps `unsigned int' > > on some oddball architectures. You must specify the promoted type, > > not the type to which you will later "demote" it. > > Yes, I know. I use "x = (char) va_arg(arg,int)" to stop gcc complaining. > But my question is why the "int $5" is generated. [...] No idea. The code as it stands (with `char' instead of `int') *is* incorrect, and the implementation of is necessarily "magical." We've all heard stories of the unexpected and usually unwelcome things that happen when sorcerers mis-pronounce their incantations; perhaps the mysterious `int $5' is one such consequence. If it goes away when the va_arg() call is corrected, I think that's a practical resolution to the problem. -- Eric Sosman esosman AT acm DOT org