Google C Overiding found that there is an English explanation:
Because C doesn ' t require that you pass all parameters to the function if you leave the parameter list blank in the Protot Ype. The compiler should only throw up warnings if the prototype have a non-empty parameter list and you don ' t pass enough enoug h arguments to the function.
In the C language, if the function prototype argument list is empty, the compiler will not ask you to pass all parameters to the function.
If the compiler discovers that the function prototype parameter list is not empty and does not pass enough arguments to the function, he should just throw a warning.
[Email protected]:~/C $ cat Param.c#include<stdio.h>voidfunc ();intMainvoid) {func (1); Func ( -,5); return 0;}voidFuncintAintb) { if(A = =1) puts ("Only going to use first argument."); Elseprintf ("Using Both arguments:a =%d, B =%d\n", A, b);} [Email protected]:~/c$ gcc-wall-ansi-pedantic PARAM.C-o param[email protected]:~/c$./paramonly going to use first argument. Using both Arguments:a= -, B =5
Actually fcnt is defined in the header file using
int fcntl (int fd, int cmd, ...);
This means it can take variable number of arguments.
Now it looks at the command and then decides if anything follows as the third parameter or not.
See Mans Va_arg etc for more details.
Usually function fcnt in the head style with int fcntl (int fd, int cmd, ...) means that he can accept an indefinite number of arguments,
You can see the details under Linux with Man Va_arg and so on.
#include <stdio.h>#include<stdarg.h>voidPrintargs (intARGS1,...)//outputs all parameters of type int until-1 ends{va_list ap; inti; Va_start (AP,ARGS1); for(i = args1; I! =-1; I =va_arg (AP,int)) printf ("%d", i); Va_end (AP); Putchar ('\ n');}intMainvoid) {Printargs (5,2, -, -, the, the, -, -,-1); Printargs ( -,Wuyi,-1); Printargs (-1); Printargs (1,-1); return 0;}
C language Overload (overriding in C) or variable number of function arguments