--- In AVR-Chat@yahoogroups.com, "Chuck Hackett" <egroupscdh@...> wrote:
> I would be using a mix of C & C++.
Not a problem. All of the prototypes for C-callable functions and all of the declarations for variables defined in C code must be within an extern "C" { } block. That tells the compiler not to mangle their names. The usual way to do this is to wrap blocks of function and variable declarations as below.
#if defined(__cplusplus)
extern "C" {
#endif
// C delarations here, e.g.
void foo(uint8_t);
extern uint16_t bar;
#if defined(__cplusplus)
}
#endif
This yields an include file that can be included in either C or C++.
Note, too, that the only functions defined in C++ that can be called from C are those that are not part of a class and whose declarations are within an extern "C" block.
Our ZBasic compiler generates either C or C++ code which is then compiled by the avr-gcc on the backend. Our ZBasic System Library comprises hundreds of functions written in C and assembly language. The only change that was required to support C++ intermediate code was to add the extern "C" block described above.
As far as symbolic debugging is concerned, C++ name mangling *may* be an issue.
Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.netMessage
Re: Mixing gcc C & C++
2012-11-27 by Don Kinzer
Attachments
- No local attachments were found for this message.