Keil STM32 C + + mixed programming Essentials
1. The filename must be. CPP and. h
2. In the. h file, add the following code:
#ifndef __ledtask_h
#define __LEDTASK_H
#ifdef __cplusplus
extern "C" {
#endif
#include " Stm32_led.h "
void Led1_task (void *pdata);
#ifdef __cplusplus
}
#endif
#endif
3. When calling resources in a. cpp file (such as classes, functions, etc.), that file must also be a. cpp file. Programs in the. cpp file that can invoke C + + syntax
4.–c99 to get rid of
In fact, in the end, I gave up the C + + mixed programming, at first very want to do so, so my part of the C + + code can be seamless porting to MFC, and later Keil also compiled, but because of the constraints of the above conditions (the first OK, the second is OK, the 3rd is bound, That others want to embed my code, must also be a CPP file, after the other person has changed the corresponding suffix name-.cpp, the file corresponding header file also has very cumbersome to add the code described in the second article; Fourth also has a binding, –c99 there is a feature that you can define variables in your code without having to define them at the beginning of the function. And you can initialize the structure, such as the following code slice:
while (1) {
int key_value = Read_key ();
}
Deviceinfo_typedef Tdeviceinfomem = {
. mac_addr = {0x84, 0x39, 0xBE, 0x90, 0x00, 0x00},
. ip_addr = {10, 1 0, 2, 1},
. netmask = {255, 255, 252, 0x00},
. Gateway = {Ten, 3, 254},
. Projbaud = 19200,
};
Of course you can do this (without –C99 support):
Deviceinfo_typedef Tdeviceinfomem = {
0x84, 0x39, 0xBE, 0x90, 0x00, 0x00},
{Ten, 2, 1},
{255, 255, 252, 0x00},
{Ten, 3, 254},
19200,
};
Considering the amount of code you have modified above, you decide not to mix programming with C + +