Dave4.12 and C++

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User7795
Level 4
Level 4
Hi,

Dave4 and C++ needs some manual help:

1) Call of DAVE.h has to be enclosed in extern "C":

extern "C" {
#include //Declarations from DAVE Code Generation (includes SFR declaration)
}


2) Preprocessor of C++ Compiler misses a symbol:

At Project -> Properties -> C/C++ Build -> Settings copy the Preprocessor symbol at C-Compiler to Preprocessor of C++-Compiler (for example XMC4500_F144x1024).

Best regards,
Wolfgang
0 Likes
4 Replies
Not applicable
Hi Wolfgang,

For compiling with C++, you can change the build properties.

Project -> Properties -> C/C++ Build -> ARM-GCC C Compiler
Command: "${ARM_GCC_HOME}/bin/arm-none-eabi-g++"


Regards,
Daryl
0 Likes
User7795
Level 4
Level 4
Hi Daryl,

thanks for the tip, but there is one consequence: not only the C++ files are now processed by g++, but also all C files, especially the Dave files. There are discussions in the web, how much the object code differs if you process a C file by g++ instead of gcc, for example here:
http://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc

My test says: at least the code size is not the same and I suppose there are risks, the Dave code compiled by g++ has not the same behavior as at the tests by Infineon using gcc. Or does Infineon test and debug the whole Dave code with gcc and g++? I would recommend it, because of the much stronger type checking of C++.

Best regards,
Wolfgang
0 Likes
User10538
Level 3
Level 3
also if you use any interrupts, you need to enclose them in main (took me a while to figure out, since the compiler doesn't warn here if you miss it, yet the ISR are never called)

Example:
extern "C" {
void ISR_Adc_Measurement(void)
{ ...}

}
0 Likes
User7795
Level 4
Level 4
Hi Andyl,

yes, the same like at Dave3 (I mentioned only the news of Dave4, there are many entries in the forum concerning Dave3 and C++). In general, if Dave calls a function located in a c++ file, the function must use the name mangling of C, done by enclosing the C++ code in
extern "C" {
..
}.

The background: because of the possibility of function overlays in C++, functions with different arguments must have different names. Thus in contrast to C, at C++ the argument types are part of the function names. The caller of Dave expects a C style function name (without argument types in the name) and the linker doesn't find the function if you don't use 'extern "C" '.

Best regards,
Wolfgang
0 Likes