[comp.sys.sgi] R2000 stack alignment question

jack@cwi.nl (Jack Jansen) (05/28/91)

After some hours of digging through assembly code I've finally found out
that varargs.h depends on the stack being aligned to an 8-byte boundary,
and the C compiler does its utmost to keep it like that (unlike me).

Could anyone in the know tell me whether this deduction is correct, and,
if so, where this is documented? I would expect this to be in the
'linkage convention' of the Kane book, but it isn't there (or, at
least, I couldn't find it...)
-- 
--
Een volk dat voor tirannen zwicht	| Oral:     Jack Jansen
zal meer dan lijf en goed verliezen	| Internet: jack@cwi.nl
dan dooft het licht			| Uucp:     hp4nl!cwi.nl!jack

kenton@abyss.zk3.dec.com (Jeff Kenton OSG/UEG) (05/28/91)

In article <3599@charon.cwi.nl> jack@cwi.nl (Jack Jansen) writes:
>After some hours of digging through assembly code I've finally found out
>that varargs.h depends on the stack being aligned to an 8-byte boundary,
>and the C compiler does its utmost to keep it like that (unlike me).
>
>Could anyone in the know tell me whether this deduction is correct, and,
>if so, where this is documented? I would expect this to be in the
>'linkage convention' of the Kane book, but it isn't there (or, at
>least, I couldn't find it...)

This is correct.  Don't really know where it's documented.

-- 
-----------------------------------------------------------------------------
==	jeff kenton		Consulting at kenton@decvax.dec.com        ==
==	(617) 894-4508			(603) 881-0011			   ==
-----------------------------------------------------------------------------

rpaul@crow.UUCP (Rodian Paul) (05/29/91)

> After some hours of digging through assembly code I've finally found out
> that varargs.h depends on the stack being aligned to an 8-byte boundary,
> and the C compiler does its utmost to keep it like that (unlike me).
> 

Don't use varargs(5) it is non-standard, use stdarg(5) instead if you want
portabilty via ANSI C.


-------------------------------------------------------------------------------
rpaul%crow@ccut.cc.u-tokyo.ac.jp	phone: +81 (3) 5706-8357
ccut.cc.u-tokyo.ac.jp!crow!rpaul	  FAX: +81 (3) 5706-8437

bh@sgi.com (Bent Hagemark) (05/31/91)

In article <9105281723.AA11513@crow.omni.co> rpaul@crow.UUCP (Rodian Paul) writes:
>> After some hours of digging through assembly code I've finally found out
>> that varargs.h depends on the stack being aligned to an 8-byte boundary,
>> and the C compiler does its utmost to keep it like that (unlike me).
>> 
>Don't use varargs(5) it is non-standard, use stdarg(5) instead if you want
>portabilty via ANSI C.

Absolutely (use stdarg(5)).  The following is from the 4.0 stdarg(5) man page:

     The va_start (ap, ParmN) macro initializes ap for subsequent use by
     va_arg and va_end.  va_start must be called before any use of va_arg.
*    The ANSI C Standard (ANSI X3.159-1989) restricts the type of parmN to one
*    of the types resulting from the default argument promotions, currently
*    int, unsigned int, pointer, or double.  If va_start is invoked with a
*    parmN which is not one of these types (e.g., if parmN is short or char)
*    the behavior is undefined.

After learing this the hard way I asked that the *'ed lines be added
to the stdarg(5) man page.

The default argument promotion rules are described in section 2.7
of K&R C, 2nd Edition.

Bent