feat: add extern "C" guards to public headers#128
Open
grzanka wants to merge 2 commits into
Open
Conversation
Wrap the installed public headers in extern "C" linkage guards so they can be included directly from C++ translation units without name-mangling link errors. Previously a C++ consumer had to wrap the include itself. Applied uniformly to all five installed headers (including the macro/enum only dedx_elements.h and dedx_error.h) so the pattern is consistent and future declarations added to any of them are covered automatically. Verified both C++ (-std=c++17) and C (-std=c11) syntax-only compiles of the public headers still succeed.
Apply the same extern "C" linkage guards to dedx.h, dedx_elements.h, dedx_tools.h, and dedx_wrappers.h, completing the set of five installed public headers so they are all usable from C++ without manual wrapping.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #128 +/- ##
=======================================
Coverage 72.73% 72.73%
=======================================
Files 12 12
Lines 1643 1643
Branches 300 300
=======================================
Hits 1195 1195
Misses 448 448 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves C++ interoperability for libdedx’s public C API by adding extern "C" linkage guards to all installed headers, ensuring declarations are not C++-mangled when consumed from C++.
Changes:
- Added
#ifdef __cplusplus extern "C" { ... } #endifwrappers toinclude/dedx.h. - Added the same C++ linkage guards to the remaining installed public headers (
dedx_elements.h,dedx_error.h,dedx_tools.h,dedx_wrappers.h) for uniformity and future-proofing.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| include/dedx.h | Wraps public API declarations in extern "C" for C++ consumers. |
| include/dedx_elements.h | Adds extern "C" guard (no-op today, keeps public surface consistent). |
| include/dedx_error.h | Adds extern "C" guard (no-op today, keeps public surface consistent). |
| include/dedx_tools.h | Wraps tool function declarations in extern "C" for C++ consumers. |
| include/dedx_wrappers.h | Wraps wrapper function declarations in extern "C" for C++ consumers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Wraps the five installed public headers in
extern "C"linkage guards:include/dedx.hinclude/dedx_elements.hinclude/dedx_error.hinclude/dedx_tools.hinclude/dedx_wrappers.hEach now has, after its include-guard
#define(and after any#includes):and the matching close before the final
#endif.Why
These headers are installed and exported via the CMake package, so they form the public API. Without
extern "C", a C++ consumer that#includes them gets C++-mangled declarations and link errors against the C-compiled library — they have to wrap the include in their ownextern "C"block. Adding the guards makes the headers directly usable from C++ with no consumer-side workaround. For C compilers the blocks are#ifdef __cplusplus-gated, so nothing changes.This addresses item #2 from the header-hygiene review discussion in #127.
Scope decision
Applied uniformly to all five installed headers, including
dedx_elements.handdedx_error.hwhich currently contain only macros/enums (nothing that mangles, so the guard is a no-op there today). The reasoning: a consistent pattern across the public surface, and any function declaration added to those headers later is covered automatically. Happy to drop the guards from the two macro-only headers if reviewers would rather keep them strictly where they're needed.Verification
g++ -std=c++17 -Iinclude -fsyntax-onlyon a TU includingdedx.h+dedx_tools.h+dedx_wrappers.h→ passes (previously this is the scenario that would mangle).gcc -std=c11 -Iinclude -fsyntax-onlyon the same headers → passes (no regression for C).https://claude.ai/code/session_01Wt7wjjWawFBS5uhRtkCYXm
Generated by Claude Code