www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/12/05:00:32

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
To: S DOT B DOT M DOT Verstege AT research DOT ptt DOT nl, djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Fri, 12 May 1995 08:28:10 BST
Subject: Re: variable amount of arguments to function

  S DOT B DOT M DOT Verstege AT research DOT ptt DOT nl (Stefan Verstege) wrote:-
> I have written a function that must accept [a] variable [amount of]
> arguments. The first argument will be the amount of arguments given to the
> function. All the arguments after this integer value, will be chars (or
> strings). When I do the following, the compiler won't accept the char type
> in the va_arg macro (I know this not allowed).. ...

  On PC djgpp (not necessarily on other computers) it works like this:-
/*-----*/
int myfunction(int nargs,...){long int*p = (long int*)&nargs;

/* The array p now contains all the arguments. p[0] = nargs. The rest of the
arguments are in order left to right in the array p, each taking up as many
elements of array p as necessary. Each argument starts at the start of an
element of array p, i.e. in argument lists the space needed by each argument
is rounded up to a multiple of 4 bytes. Remember that (1) PC computers are
little-endian (= units byte to left in values), but some other computers
aren't; (2) int is default 4 bytes in Gnu C, but default 2 bytes in some other
PC C's. I don't muck about with va_arg, I look at the argument list myself. */

- Raw text -


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