P
pkpatil
Hi,
I recently saw a code with a mix of C & C++, wherein a C++ file was
calling a C function dropping the last argument. The code was similar
to below:
--------------------------------------------------------------------------------------------------------------
cfile.c
---------
C_Fun(int arg1, int arg2, int arg3) { // C function with three
parameters
}
cppfile.cpp
----------------
extern "C" { C_Fun(int arg1, int arg2); } //Note: declaring the C
function as taking only two parameters
OtherFunction() {
int first, int second;
C_Fun(first, second) //Note: passing only two parameters
}
--------------------------------------------------------------------------------------------------------------
This code did get built when linked together (using gcc), but how is
this allowed? Is the last argument to C function, "arg3" treated as
default argument with value of zero as
"C_Fun(int arg1, int arg2, int arg3=0);" ?
Thanks,
PK
I recently saw a code with a mix of C & C++, wherein a C++ file was
calling a C function dropping the last argument. The code was similar
to below:
--------------------------------------------------------------------------------------------------------------
cfile.c
---------
C_Fun(int arg1, int arg2, int arg3) { // C function with three
parameters
}
cppfile.cpp
----------------
extern "C" { C_Fun(int arg1, int arg2); } //Note: declaring the C
function as taking only two parameters
OtherFunction() {
int first, int second;
C_Fun(first, second) //Note: passing only two parameters
}
--------------------------------------------------------------------------------------------------------------
This code did get built when linked together (using gcc), but how is
this allowed? Is the last argument to C function, "arg3" treated as
default argument with value of zero as
"C_Fun(int arg1, int arg2, int arg3=0);" ?
Thanks,
PK