Hi,
I would like to know if "C" allows one to put default values in function prototypes like in "C++?"
Here is an example:
int SetName( char *pchName, BOOL fNewName = TRUE );
Thanks!
Hi,
I would like to know if "C" allows one to put default values in function prototypes like in "C++?"
Here is an example:
int SetName( char *pchName, BOOL fNewName = TRUE );
Thanks!
I tried it with Visual C++ 6, and it doesn't allow it. Is it actually in the ISO C standard?
Yes, it should be ANSI/ISO standard. But standards don't bother MS compilers very much
What code did you try to compile?!
Greetings
cody
#include "reallife.h"
This is what I have in my header file:
/* sc.h */
sc_error_t DllDeclare SCSetUser_Privilege_IPSecAPIKey(
char *pchUserKey,
char *pchPrivilegeKey,
BOOL fSA = TRUE,
BOOL fNewPW = TRUE );
This is in my source file:
/* sc.c */
sc_error_t DllDeclare SCSetUser_Privilege_IPSecAPIKey(
char *pchUserKey,
char *pchPrivilegeKey,
BOOL fSA,
BOOL fNewPW )
{
sc_error_t eErr = SC_OK;
...
return eErr;
}
On the prototype line of BOOL fSA the following errors:
syntax error : missing ')' before '='
and
'SCSetUser_Privilege_IPSecAPIKey' : initialization of a function
I have also touched base with the comp.lang.c newsgroup. So far I received one reply on the question. ("No")
I have now decided to write Dennis Ritchie himself to find out.
Have you tried to compile it without the default values?
#include "reallife.h"
Then it is fine!
Well, i guess my "jep it does" was wrong then and default arguments are indeed a c++ feature. I changed from c to c++ a longer time ago, but really thought I could remember using default arguments in normal c. Hmm....damn...I'm getting old
Sorry
Greetings
cody
#include "reallife.h"
Yea, I've been on C++ since '94 and didn't know if C was updated to handle default values for function prototype parameters.
We're busy with a very intense project that is cramped into a very short time. Unfortunately we have to make use of legacy C code.
...good luck then
...and I could have sweared, that I've used default arguments in a C proggy...well...
Have a nice day
cody
#include "reallife.h"
No, not in C89 one can't , I dunno about C99
Originally posted by cody
...good luck then
...and I could have sweared, that I've used default arguments in a C proggy...well...
Have a nice day
cody
I was in contact with Dennis Ritchie of "Kernigan and Ritchie" fame, and he said he doesn't think it is in C99, and definitely wasn't in previous standards.
It is such a pity!
I know for a fact that C does not support default arguments. Perhaps in the newest draft they've added it, but in "classic C" (meaning as it was originally made) it does not support default arguments.
The reason it may be working for you is because you're using a C++ compiler, and compiling as C++ rather than C, which, C++ handles C and then C++, thus ending up with it accepting the arguments. That's my guess.
Quzah.
I originally started this thread because it was not working under Visual C++, and thought that perhaps it was just MS that did not comply with the C standard, but alas, the standard says no!