This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Calling C++ from C

I'm testing some ideas using the EC++ compiler for C166. I've found that when I want to call a C function from a C++ file I have to prototype the function

extern "C" void myfunc(void);

I'm struggling to find how to call a function in a C++ from a C file. I can see from the m66 file that a function in a cpp file gets named myfunc__Fv. I can prototype my function

void myfunc__Fv(void);

and it compiles OK. Is there a directive that tells the compiler to use the correct naming convention?

(Why? I have a test project which is currently built in plain C. I want to try out some extensions to it in C++. In main have called a function InitCpp which is implemented in InitCpp.cpp - a c++ file. This initialises the mempool, calls __sti__init__ and defines new and delete. However I can't call InitCpp, I get an unresolved external InitCpp since the EC++ compiler calls it InitCpp__Fv. I can fudge it by prototyping as above but wanted to know if there was a way of doing this by design. I cannot find extern "C" in the help since search finds all occurances of C when I try. I was hoping that the manual page describing extern "C" would offer whatever extern "CPP" is. I suspect there nothing unless Keil have modified the plain C complier to support the C++ calling convention.)

Thanks for any ideas
A

IDE-Version:
µVision V4.00a
Copyright (c) Keil Elektronik GmbH / Keil Software, Inc. 1995 - 2009

License Information:
Alec James
Talaris
LIC=xxxxx-xxxxx-xxxxx-xxxxx-xxxxx-xxxxx

Tool Version Numbers:
Toolchain: PK166 Prof. Developers Kit Version: 7.00
Toolchain Path: d:\Keil\C166\BIN\
EC++ Compiler: EC166.Exe V1.09d
C Compiler: C166.Exe V7.00
Assembler: A166.Exe V5.33
Linker/Locator: L166.Exe V5.25
Librarian: LIB166.Exe V4.26
Hex Converter: OH166.Exe V4.7a
CPU DLL: S166.DLL V3.74
Dialog DLL: D167.DLL V2.52