PDA

View Full Version : dont pass an argument


alaios
07-14-2005, 09:23 AM
Hi i have the following function declaration
void logfile(char *string,FILE *fp){
....
}

If i want to call it and dont pass any argument for the file what should i do?
I have tried the following and didnt worked

logfile(mystring,void)
then i have tried the
logfile(mystring,NULL) and worked
can u plz shed some light on this .... and explain me why?
Thx a lot have a nice day

Dr. Evil
07-14-2005, 09:44 AM
Trying to pass void won't work because void's a datatype, thus you wouldn't be passing anything and you'd most likely get a syntax error. NULL, on the other hand, is defined as (void*)0, so you're essentially passing zero as the parameter.

shmoove
07-14-2005, 10:04 AM
If the logfile function is coded so that it knows how to handle the lack of the second parameter, then using NULL or 0 should work.

if you're using a C++ compiler then you can also use the optional parameter syntax:

void logfile(char *string,FILE *fp = NULL){

and then you can use logfile with only one parameter.

shmoove

alaios
07-14-2005, 12:08 PM
thx for your answer,,, but what do u mean void is declared as a datatype... can u give me the header file to check it (linux os)
thx and have a nice day