Drop IMGUI_STB_NAMESPACE so dcimgui_internal.h compiles as C - #604
Open
pusewicz wants to merge 1 commit into
Open
Drop IMGUI_STB_NAMESPACE so dcimgui_internal.h compiles as C#604pusewicz wants to merge 1 commit into
pusewicz wants to merge 1 commit into
Conversation
Dear Bindings v0.19 leaves C++ scope syntax (ImStb::stbrp_node) in the namespaced branch of dcimgui_internal.h, so with the namespace set the header failed in C, and in any C++ file that did not include imgui_internal.h first. The only reason CF set the namespace was cute_draw.cpp, which compiled stb_truetype's implementation next to imgui_internal.h in one translation unit; those imgui includes were dead. Remove the dead includes and the define, and put dcimgui_internal.h's stbrp block back to the generator's layout, so the generated headers carry no CF patches. Also wrap imconfig.h's cute_math.h include in extern "C++": dcimgui.h includes imconfig.h from inside extern "C", which broke any C++ file that included dcimgui.h before cute.h. Two guard tests cover both: test_dcimgui.c (internal header from plain C) and test_dcimgui.cpp (dcimgui.h before cute.h). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013dQLMKSRz7vi8PHh9BQ5Jb
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes are coherent with the stated failure modes and are guarded by new C and C++ compilation-order tests that should catch regressions.
Pull request overview
This PR adjusts Cute Framework’s Dear ImGui integration to eliminate the IMGUI_STB_NAMESPACE configuration (which caused dcimgui_internal.h to be non-C-compilable due to C++ scope syntax), and fixes a C++ include-order/linkage issue caused by dcimgui.h including imconfig.h from inside an extern "C" block. It also adds tests to guard both behaviors.
Changes:
- Remove
IMGUI_STB_NAMESPACEusage from CF’s Dear Bindings headers and related CF TU include patterns. - Fix C++ linkage when
imconfig.hincludescute_math.hvia a narrowextern "C++"restoration. - Add C and C++ compilation-order tests for
dcimgui.h+dcimgui_internal.h, plus a short docs note.
File summaries
| File | Description |
|---|---|
test/test_dcimgui.cpp |
Adds a C++ compile-order guard test (dcimgui headers included before cute.h). |
test/test_dcimgui.c |
Adds a pure-C guard test that includes dcimgui_internal.h and touches internal API symbols. |
test/main.cpp |
Registers the new dcimgui test suites in the test runner. |
test/CMakeLists.txt |
Adds the new C and C++ test sources to the tests target. |
src/cute_draw.cpp |
Removes ImGui header includes from the TU that compiles stb_truetype implementation. |
libraries/imgui/imconfig.h |
Restores C++ linkage around #include <cute_math.h> to avoid extern "C" issues. |
libraries/imgui/dcimgui.h |
Stops defining IMGUI_STB_NAMESPACE in the generated C bindings header. |
libraries/imgui/dcimgui_internal.h |
Aligns the ImVector_stbrp_node_im_t instantiation with the non-namespaced branch. |
docs/topics/dear_imgui.md |
Documents supported include order and how to include dcimgui_internal.h. |
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Dear Bindings v0.19 leaves C++ scope syntax (
ImStb::stbrp_node) in the namespaced branch ofdcimgui_internal.h, so withIMGUI_STB_NAMESPACEset the header failed from C, and from any C++ file that did not includeimgui_internal.hfirst. Reaching the DockBuilder from a C game needed an#undefbetween the two includes.The only reason CF set the namespace was
cute_draw.cpp, which compiled stb_truetype's implementation next toimgui_internal.hin one TU. Nothing there used ImGui, so the includes go and the define goes with them. The generated headers now carry no CF patches.Separately,
dcimgui.hincludesimconfig.hfrom insideextern "C", which broke any C++ file that includeddcimgui.hbeforecute.h.imconfig.hnow restores C++ linkage around itscute_math.hinclude.Both cases have guard tests. Trade-off: this restores vanilla ImGui behavior, so a downstream C++ TU that compiles its own stb_truetype implementation next to
imgui_internal.hwould clash, ascute_draw.cppdid.🤖 Generated with Claude Code
https://claude.ai/code/session_013dQLMKSRz7vi8PHh9BQ5Jb