as title
as title
You don't. C is not C++ and doesn't support that feature. If you really wanted to you could use the preprocessor though:
Code:#define f1(a) f ( (a), 0, 0, 0 ); #define f2(a, b) f ( (a), (b), 0, 0 ); #define f3(a, b, c) f ( (a), (b), (c), 0 ); #define f4(a, b, c, d) f ( (a), (b), (c), (d) ); void f ( int a, int b, int c, int d );
My best code is written with the delete key.
why define f1 .....f4?
Is thats mean when i call the function
right?Code:f(1); /* it pass in f( 1 , 0, 0, 0); */
but why i need to define in this way
can i do this
Code:#define fa( a ) f( (a), 0 , 0, 0 ); #define bbx( a, b ) f( (a), (b) , 0, 0);
oooh.. i got it... blur
that mean when i want to pass in one arg
f1(2);/* ---> f(2, 0, 0,0) */
then it is no so convenient way...
one of my friend seen an example that using an external header to archive .. is that possible?
>one of my friend seen an example that using an external header to archive ..
I have no idea what you're talking about. Can you try to describe it better?
My best code is written with the delete key.
I suppose you could neaten up the calling of the function slioghtly by using a variable argument list.
This uses <stdarg.h>, is that what you meant by external header file??
The down side is you would have to pass the number of arguments you were using each time. Then save them one after the other to the variables you want, and set the rest as defaults inside the function. You can still only use arguments consecutively in the order you specify. ie
for
void f(int num_args, ...);
you could do
f(1,2); /*Passing one argument - rest default*/
but not
f(1,,2); /*Second argument missing*/
which is the same as in Prelude's way. It would also be less efficient than Prelude's - take your pick.
Davey