Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!news.funet.fi!funic!santra!santra!ahuttune From: ahuttune@niksula.hut.fi (Ari Juhani Huttunen) Newsgroups: comp.std.c++ Subject: Variable arguments (Was Re: type/member tags Message-ID: Date: 2 Mar 91 13:44:31 GMT References: <27C95D3A.1715@tct.uucp> <1991Feb27.154311.782@csc.ti.com> <27CD159D.6581@tct.uucp> Sender: news@santra.uucp (Cnews - USENET news system) Organization: Helsinki University of Technology, Finland Lines: 31 In-Reply-To: chip@tct.uucp's message of 28 Feb 91 14:37:17 GMT Suppose I want to write a function that takes as its arguments any number of integers and returns the largest of these integers. This can be implemented using constructs already found in the language. IF you a) tell the function as the first argument how many integers you will supply to it or b) as the last argument you give a predefined constant that means there are no more arguments. This is error prone, I think. The problem is that C++ doesn't give any means to check how many arguments were supplied or their types. If typeof() would be added to C++, the problem could perhaps be solved this way: int max(int x1 ...) { va_list argp; va_start(argp, x1); while(typeof(*argp) == int) { int x2 = va_arg(argp, int); if(x2>x1) x1=x2; } va_end(argp); return x1; } When there are no more arguments, typeof(*argp) == void. -- ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ I I__I I__I I__I I__I I__I I__I I__I I__I I__I I__I I__I I__I I__I I__I I__I I_ Ari Huttunen A computer is like a house of cards. Not as reliable, but it has an equal number of incompatible parts. _______________________________________________________________________________