Nuclei-Software / nuclei-sdk

Nuclei RISC-V Software Development Kit
https://doc.nucleisys.com/nuclei_sdk
Apache License 2.0
117 stars 50 forks source link

Wrap declarations when including from C++ #38

Closed gsauthof closed 2 years ago

gsauthof commented 2 years ago

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 commented 2 years ago

LGTM, I will merge it when CI passed