Skip to content

feat: add extern "C" guards to public headers#128

Open
grzanka wants to merge 2 commits into
mainfrom
claude/libdedx-deps-review-beQBi
Open

feat: add extern "C" guards to public headers#128
grzanka wants to merge 2 commits into
mainfrom
claude/libdedx-deps-review-beQBi

Conversation

@grzanka
Copy link
Copy Markdown
Contributor

@grzanka grzanka commented Jun 6, 2026

What

Wraps the five installed public headers in extern "C" linkage guards:

  • include/dedx.h
  • include/dedx_elements.h
  • include/dedx_error.h
  • include/dedx_tools.h
  • include/dedx_wrappers.h

Each now has, after its include-guard #define (and after any #includes):

#ifdef __cplusplus
extern "C" {
#endif

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 own extern "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.h and dedx_error.h which 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-only on a TU including dedx.h + dedx_tools.h + dedx_wrappers.hpasses (previously this is the scenario that would mangle).
  • gcc -std=c11 -Iinclude -fsyntax-only on the same headers → passes (no regression for C).
  • Pure documentation/guard change — no functional code touched.

https://claude.ai/code/session_01Wt7wjjWawFBS5uhRtkCYXm


Generated by Claude Code

grzanka added 2 commits June 6, 2026 11:26
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
Copy link
Copy Markdown

codecov Bot commented Jun 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.73%. Comparing base (36990c2) to head (ef43ab5).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" { ... } #endif wrappers to include/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.

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