cdecl keyword in MSC

Stephen J. Friedl friedl at vsi.UUCP
Sun Apr 3 09:29:39 AEST 1988


In article <185 at premise.ZONE1.COM>, chang at premise.ZONE1.COM writes:
> 
> [ comments about "useless" cdecl and function calling conventions in MSC ]
>
> The calling convention we're talking about here isn't call-by-name or
> call-by-value.  It's simply the order in which parameters are passed
> on the stack.  And in C, that order *must* be right to left in order
> to support variable length functions like printf.  If it were left to
> right, then the printf function wouldn't know where to find its format
> string.

Note that while right-to-left arg passing may be used in the PC,
this is defined *by* the PC and/or MSC and not by the C language
(it is specifically "Unspecified Behavior").  There are indeed
machines such as the WE32100 (AT&T 3B2) and I believe the PDP-11
that are happy to pass args in the other direction, and *my* 3B2
printf() still says "hello, world\n" :-)

My limited cause-and-effect detectors indicate that when the
stack grows up (i.e., "push" increments the stack pointer) then
args go left->right, and if the stack grows down then args go
right->left.  Upward-growing stacks seem to be much less common;
anybody know of others?  Which direction do their args pass?

Also, I imagine that a clever compiler writer could manage to
define a calling convention that would work properly in either
direction, albeit less efficiently in the "wrong" direction.

Try this on your favorite compiler to see what you get.

	main()
	{
	static char	*dirwords[] = { "left", "right" };
	char		**dirptr = dirwords;

		printf("Direction is %s to %s\n", *dirptr++, *dirptr++);
	}

-- 
Steve Friedl   V-Systems, Inc.   "Yes, I'm jeff at unh's brother"
friedl at vsi.com {uunet,ihnp4}!vsi.com!friedl attmail!vsi!friedl



More information about the Comp.lang.c mailing list