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

Add extern "C" to headers for easier use by C++ #207

Merged
merged 1 commit into from
Feb 3, 2022

Conversation

tedbrandston
Copy link
Contributor

Add extern "C" directly to all headers except efivar-guids.h, which
is generated. Because it interferes with C compilers, wrap each
extern in an #ifdef __cplusplus. For efivar-guids.h update the
generator, makeguids.c, to add the desired code.

From https://en.cppreference.com/w/cpp/language/language_linkage:

extern "C" makes it possible to include header files containing
declarations of C library functions in a C++ program, but if the
same header file is shared with a C program, extern "C" (which
is not allowed in C) must be hidden with an appropriate #ifdef,
typically __cplusplus.

fixes #205

Tests:

  • make and make test both work
  • tested in my project with extern "C" removed from my code.

Add `extern "C"` directly to all headers except efivar-guids.h, which
is generated. Because it interferes with C compilers, wrap each
`extern` in an `#ifdef __cplusplus`. For efivar-guids.h update the
generator, makeguids.c, to add the desired code.

From https://en.cppreference.com/w/cpp/language/language_linkage:
> extern "C" makes it possible to include header files containing
> declarations of C library functions in a C++ program, but if the
> same header file is shared with a C program, extern "C" (which
> is not allowed in C) must be hidden with an appropriate #ifdef,
> typically __cplusplus.

Signed-off-by: Ted Brandston <tbrandston@google.com>
@frozencemetery frozencemetery merged commit 28789d1 into rhboot:main Feb 3, 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.

Add properly gated extern "C" to public headers
2 participants