Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap declarations when including from C++ #38

Merged
merged 1 commit into from
May 5, 2022

Conversation

gsauthof
Copy link
Contributor

@gsauthof gsauthof commented May 1, 2022

Motivation: Previously, one had to remember to always include SDK
headers from a C++ translation unit like this:

extern "C" {
#include <gd32vf103_rcu.h>
#include <gd32vf103_gpio.h>
}

Which arguably is a bit tedious and errorprone. And when leaving those
out it's perhaps not entirely obvious to beginners why they are getting
weird linker errors.

This commit thus wraps all the SDK API headers inside appropriate guards
using with the following macros

GD32VF103_BEGIN_DECLS
GD32VF103_END_DECLS

such that a C++ translation can include them simply via e.g.:

#include <gd32vf103_rcu.h>
#include <gd32vf103_gpio.h>

Note that this pattern follows what other libraries such as the Glibc,
Glib or GSL do with their headers.

Motivation: Previously, one had to remember to always include SDK
headers from a C++ translation unit like this:

    extern "C" {
    #include <gd32vf103_rcu.h>
    #include <gd32vf103_gpio.h>
    }

Which arguably is a bit tedious and errorprone. And when leaving those
out it's perhaps not entirely obvious to beginners why they are getting
weird linker errors.

This commit thus wraps all the SDK API headers inside appropriate guards
using with the following macros

    GD32VF103_BEGIN_DECLS
    GD32VF103_END_DECLS

such that a C++ translation can include them simply via e.g.:

    #include <gd32vf103_rcu.h>
    #include <gd32vf103_gpio.h>

Note that this pattern follows what other libraries such as the Glibc,
Glib or GSL do with their headers.
@fanghuaqi
Copy link
Member

LGTM, I will merge it when CI passed

@fanghuaqi fanghuaqi merged commit 430221d into Nuclei-Software:develop May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants