Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!decuac!cvl!mimsy!chris From: chris@mimsy.UUCP Newsgroups: comp.sources.d,comp.lang.c Subject: varargs (was Re: Public Domain _doprnt in C) Message-ID: <6152@mimsy.UUCP> Date: Mon, 6-Apr-87 05:00:03 EST Article-I.D.: mimsy.6152 Posted: Mon Apr 6 05:00:03 1987 Date-Received: Thu, 9-Apr-87 01:45:29 EST References: <938@copper.TEK.COM> <100@asi.UUCP> <2285@ncoast.UUCP> Followup-To: comp.lang.c Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 56 Xref: utgpu comp.sources.d:547 comp.lang.c:1489 In article <2285@ncoast.UUCP> allbery@ncoast.UUCP (Brandon Allbery) writes: >Note that varargs is defined such that it will work even on machines such as >the Pyramid which pass arguments in registers (common on RISC machines). Or on the MIPS machines. >You MUST declare only one argument -- va_alist -- and include the type of it >as "va_dcl" without a semicolon. `va_alist' and `va_dcl' are often (always?) macros. It is conceivable that on a machine that passes the first two arguments in registers and the third through nth on the stack, these might be #define va_alist _p1, _p2, _p3 #define va_dcl int _p1, _p2, _p3; in which case va_start might be #define va_start(l) { \ struct _va_info _va; \ _va.reg = 2; _va.r[1] = _p1; _va._r[0] = _p2; \ _va.addr = &_p3; \ (l) = &_va; and va_arg then #define va_arg(l, t) \ (sizeof(t) == 8 ? \ /* size always 8 or 4 in this arch. */ (ugly code to handle double float with spanning &c) : \ (--(l)->reg >= 0 ? *(t *)&(l)->r[(l)->reg] : \ ((l)->addr++, ((t *)((l)->addr))[-1]))) (and va_end would simply be defined as `}'). This would indeed preclude usage like f(fmt, va_alist) char *fmt; va_dcl { ... The reason I mention this is that in fact, on the Pyramid, Sun, and Vax (all implementations of which I am aware), usages such as that above in fact work. I wonder, then, if this has been guaranteed anywhere. Has it? (I know, I should dig out a copy of the X3J11 draft....) >(C compilers can then recognize this directly to do any special >processing needed, as for the Pyramid.) Actually, Pyramid manages it without compiler hooks. I believe MIPS uses compiler hooks, though. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!mimsy!chris ARPA/CSNet: chris@mimsy.umd.edu