Xref: news2.mv.net comp.os.msdos.djgpp:3668 From: alexlehm AT rbg DOT informatik DOT th-darmstadt DOT de (Alexander Lehmann) Newsgroups: comp.os.msdos.djgpp Subject: Re: vararg Date: 9 May 1996 22:49:41 GMT Organization: Technische Hochschule Darmstadt Lines: 55 Message-ID: <4mtsq5$19om@rs18.hrz.th-darmstadt.de> References: <4mt88s$q5r AT rs18 DOT hrz DOT th-darmstadt DOT de> NNTP-Posting-Host: hp62.rbg.informatik.th-darmstadt.de To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Alexander Lehmann (alexlehm AT rbg DOT informatik DOT th-darmstadt DOT de) wrote: : Eli Zaretskii (eliz AT is DOT elta DOT co DOT il) wrote: : : On Wed, 8 May 1996 kagel AT quasar DOT bloomberg DOT com wrote: : : > void abc(int anzahl, unsigned char abc, ...) : : > { : : > va_list ap; : : > va_start(ap, abc); : : > fg = va_arg(ap, unsigned char); : : > : : > : : > The problem is that when you call a variable argument function the arguments : : > beyond the list of predefined arguments are all promoted (char and short to : : > int, float to double) so you cannot get an unsigned char here. What you are : : In addition to all that's been said on this thread by Art and others, the : : above is explicitly forbidden by ANSI C. : I don't have the ANSI spec, but the following is from the hpux man-page of : stdarg (where the C compiler has a K&R and ANSI mode): : WARNINGS : Unless ANSI C is used, it is non-portable to specify a second argument : of char, short, or float to va_arg, because arguments seen by the : called function are never char, short, or float. : Pre-ANSI C converts char and short arguments to int and converts float : arguments to double before passing them to a function. : From this I would guess that when ANSI C is used, it is allowed to use the : smaller size types (and it is obviously handled in the stdarg include in gcc), : the problem arises from the use of a smaller type parameter before the ... : (see my previous post). From the comment at the top of the stdarg.h file that comes with gcc 2.7.2, I would now guess that it should be promoted type, but it seems that the definitions can handle the use of smaller types as well. The solution to problem seems to be to use __builtin_next_arg instead of the address of the variable as is used in stdarg.h in gcc 2.7.2 (thanks to Alexander Lukyanov for pointing that out). This way it works, even if the variable is copied locally. This function even complains if you feed it the incorrect variable name. If this would work with register calling also, I am not sure. bye, Alexander -- Alexander Lehmann, | "On the Internet, alex AT hal DOT rhein-main DOT de (plain, MIME, NeXT) | nobody knows alexlehm AT rbg DOT informatik DOT th-darmstadt DOT de (plain) | you're a dog."