Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Variable Parameters Message-ID: <1989Dec31.013746.2349@utzoo.uucp> Organization: U of Toronto Zoology References: <1169@zip.eecs.umich.edu> Date: Sun, 31 Dec 89 01:37:46 GMT In article <1169@zip.eecs.umich.edu> bagchi@dip.eecs.umich.edu (Ranjan Bagchi) writes: > I'm working, currently, on a project that involves a function that >could take any number or arguments. I would like to pass it only >those arguments, i.e. no "flags" at the end which tell the function >to stop. Your function has to have some way of knowing how many arguments there are, or which is the last argument. The language does not provide any built-in way for you to discover this. The usual approaches are a terminator argument of some kind, an argument count passed as the first argument, or an implicit count embodied in an early argument (e.g., you can tell how many arguments a printf() has by analyzing the format string). You have to do one of these things. > I'm using ANSI C, and believe my options are either to pass >the function an array, or to use the elipsis for unspecified. By far the simplest method is to pass an array with either a terminator flag in the array or a count as a separate argument. The ellipsis will not solve the problem for you, and proper use of it is complex. -- 1972: Saturn V #15 flight-ready| Henry Spencer at U of Toronto Zoology 1989: birds nesting in engines | uunet!attcan!utzoo!henry henry@zoo.toronto.edu