This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Please can you add extern "C" as appropriate to your header files?

Hi,

Many of us use C++ rather than C (as it is superior in every way). When including many of the Nordic SDK header files it is necessary to wrap them in

extern "C" {
}

to get the proper linkage. Otherwise you get cryptic error messages like "impossible constraint in ‘asm’".

The standard practice to avoid this necessity is to add the extern wrapper to the header code where appropriate like this:

#ifdef __cplusplus
extern "C" {
#endif

// ...

#ifdef __cplusplus
}
#endif

But you haven't done that in any of the headers. Please can you do so?

Parents
  • I would vote for the C++ include guards, too!

    This is standard style if a C interface supports C++, even if "support" means "is not painful to use". Cognitive style is very important in C, so using "standard" idioms, such as __cplusplus guards, really helps take the cognitive load off of a developer.

    Also, the mbed platform is C++ only, and I know that Nordic is supporting that, so I would assume that C++ is actually, to some extent, already supported by Nordic using a mbed branch of the SDK!

Reply
  • I would vote for the C++ include guards, too!

    This is standard style if a C interface supports C++, even if "support" means "is not painful to use". Cognitive style is very important in C, so using "standard" idioms, such as __cplusplus guards, really helps take the cognitive load off of a developer.

    Also, the mbed platform is C++ only, and I know that Nordic is supporting that, so I would assume that C++ is actually, to some extent, already supported by Nordic using a mbed branch of the SDK!

Children
No Data
Related