ahuttune@niksula.hut.fi (Ari Juhani Huttunen) (03/02/91)
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. _______________________________________________________________________________