We are trying a modify some existing C projects i.e. we are trying to make some C++ function calls from the C code. We tried changing compiler from gcc to g++ but there were several compilation errors because of incompatibality. What we are trying to do is to call some C++ functions in C code without making any change to existing code. Simply changing the compiler didn't seem to do the trick. Hence we tried following:
#include <stdio.h>
extern "C"
{
int func(int new ) {
printf("in new func()\n");
}
}
When i compile it using command
g++ -c hello.c -o hello
we get following errors
hello.c:9: error:expected ‘,’ or ‘...’ before ‘new’.
Now we are aware that new is c++ keyword. As mentioned before, we are trying not to make any modifications to existing C code. Any suggestions ?
These aren't the only errors. There are other errors related to structure declaration.
attr.c:75: error: expected primary-expression before ‘.’ token
At attr.c, line 75 is
static post_op_attr error_attr = {.attributes_follow = FALSE };
The problem is that there are other C styled structure declaration and initialization done in the code so even if we rename the variable name, we would still have to modify other parts of the C program. Hence we are looking for a way to add C++ function calls to C code without modifying existing C code.