www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/09/17:07:23

Xref: news2.mv.net comp.os.msdos.djgpp:3639
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 16:59:08 GMT
Organization: Technische Hochschule Darmstadt
Lines: 51
Message-ID: <4mt88s$q5r@rs18.hrz.th-darmstadt.de>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 960509065259 DOT 19582A-100000 AT is>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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).



BTW. this would be another obstacle for using register calling, since when
all fixed parameters are passed in registers, it is not possible to take a
pointer to index the variable arguments list. I think BCC handles this by using
a pseudo variable ..., which contains the address of the first ... argument,
something like this would have to be introduced in gcc also.


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."
<URL:http://www.student.informatik.th-darmstadt.de/~alexlehm/>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019