Keil STM32 C + + mixed programming Essentials __linux

Source: Internet
Author: User
Tags mixed
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 + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.