<stdarg.h>, variable argument lists

Steven F. LeBrun lebrun at LL.MIT.EDU
Tue Feb 12 02:33:50 AEST 1991


I am working on a SUN 4/370 Sparc computer running SunOS 4.0 and using the
GNU GCC Compiler version 1.39.  I am developing code that uses the ANSI
method for passing variable length argument lists to functions.  Since neither
the SUN CC compiler or the GCC compiler supplies the <stdarg.h> header file,
I wrote my own.  My version of <stdarg.h> works well in most cases but there
is one function where I cannot get it to work.  It appears that the arguments
are not being passed on the stack as expected.  All evidence indicates
that the stdarg.h macros are accessing the section of the stack that should
contain the arguments only there are no arguments there.  

The GCC documentation states that `GNU CC is normally configured to use the
same function calling convention normally in use on the target system.'   
I am looking for information on the SUN's or GNU GCC's function calling 
convention for C functions, especially any case that would cause the arguments 
not to passed on the stack.  I am also looking for information on whether 
there is any GNU GCC option that will force the arguments to be passed on 
the stack.

Please send any responses directly to me using my Internet Address since I
do not have access to the comp.lang.c newsgroup.  I have enclosed sections of 
the afflicted code including my version of <stdarg.h>.  I thank you in advance 
for any help that you may give.
-------------------------------------------------------------------------------
The code from my version of <stdarg.h>:

#if !defined(STDARG_H)
#define      STDARG_H    included

typedef  char*    va_list;

#define  va_start(ap,alast) ap = (va_list) (((int) &alast) + sizeof(alast))

#define  va_arg(ap, atype)  *( (atype *)                                    \
			     ((ap = (va_list)                               \
			     ((((int) ap) + sizeof(atype) + 0x03) & ~0x03)) \
			     - sizeof(atype)))

#define  va_end(ap)          

#endif  /* If !defined(STDARG_H) */

NOTE: The `+ 0x03) & ~0x03' in va_arg() performs 4-byte boundry alignment.  
      This is different from the way it is done in the SUN's version of 
      <varargs.h> and it takes care of any argument that is smaller than 
      four bytes that is placed on the stack as an int.
-------------------------------------------------------------------------------
The following is the prototype of the misbehaving function:

int   Get_OBJECT          (LORDS_RETURN *, OBJECT_TABLE *, int, ...  );

where LORDS_RETURN and OBJECT_TABLE are user defined types.


+--------------------------------------------------------------------------+
| Steven F. LeBrun                    MIT Lincoln Laboratory, Group 91     |
|                                         Millstone Hill Radar             |
| lebrun at ll.mit.edu (Internet)            Westford, MA 01886               |
| lebruns at betel     (internal)    Phone:(617)-981-5742, FAX:(617)-981-5636 |
+--------------------------------------------------------------------------+



More information about the Comp.lang.c mailing list