Newsgroups: comp.os.minix Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Important new program: cleanit.c Message-ID: <1989Oct8.025909.13399@utzoo.uucp> Organization: U of Toronto Zoology References: <3492@ast.cs.vu.nl> <3498@solo10.cs.vu.nl> <3539@ast.cs.vu.nl> <3554@solo2.cs.vu.nl> Date: Sun, 8 Oct 89 02:59:09 GMT In article <3554@solo2.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: >\ ... just leaving out >\ the last actual parameter. Given the C calling sequence of pushing the >\ last parameter first, this is legal, [...] > >I think it's always illegal: there might exist machines with `weird' calling >conventions which would choke over such mis-invocations (while still allowing >varargs functions). (Aside: could you comment on that, Henry?) The order of parameter pushing has never been defined; in fact, order of evaluation of parameters, and stack layout of same, has always been quite explicitly undefined. (Even K&R 1st ed. specifically warns that compilers differ.) In pre-ANSI C, there was no officially-blessed way to call a function with arguments not matching those at the function's definition. (The header existed in V7 but was not documented.) Printf and friends had to be done *somehow*, with a strong implication that the method was implementation-specific and collaboration with the compiler was needed. ANSI C blesses mismatches specifically and only for varargs functions. In practice, the usual approach to printf was to have the compiler use a push order that put the first argument in a predictable place, which usually meant last-first so that the first argument was at the top of the stack. This had the side effect of making trailing arguments optional in general. Exploiting this is probably not a good idea; the portability problems are substantial and growing. Varargs functions do not necessarily use the same calling sequence as ordinary ones. -- A bit of tolerance is worth a | Henry Spencer at U of Toronto Zoology megabyte of flaming. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu