Skip to content

Exporting a C/C++ header document writes Name.cpp / Name.c containing #pragma once instead of a .h/.hpp header #367

Closed

Description

@matt-edmondson

What's wrong

SourceFile.IsHeader (Coder/Ast/SourceFile.cs:70) tells the C and C++ generators to produce a header: CFamilyGenerator.WriteFileDirectives (Coder/Languages/CFamilyGenerator.cs:81-86) emits #pragma once when it is set.

The editor's export ignores the flag when naming the output file. CoderEditorApp (Coder.Editor/CoderEditorApp.cs:582) always writes {stem}.{generator.FileExtension}, and FileExtension is fixed:

  • "cpp" in Coder/Languages/CppGenerator.cs:90
  • "c" in Coder/Languages/CGenerator.cs:167

Failure scenario

  1. Create Physics.coder.yaml whose root is a SourceFile with Header ticked and a struct inside.
  2. Preview it as C++ and choose Export.
  3. The editor writes Physics.cpp, and the file starts with #pragma once.

What follows:

  • #include "Physics.h" (or .hpp), for example from another document's Imports, cannot find the file.
  • Compiling the file as a translation unit makes gcc/clang warn "#pragma once in main file".
  • A build that globs *.cpp compiles the header as its own unit, and also compiles it again wherever it is included.

C has the same problem: the export writes Physics.c.

Suggested fix / acceptance criteria

  • When the exported root is a SourceFile with IsHeader, C exports .h and C++ exports .h or .hpp (choose one and document it). Either add a header-extension member on the C-family generators (or ILanguageGenerator) that export consults, or resolve the extension from IsHeader in the editor.
  • Documents that are not headers keep .c and .cpp.
  • The other languages are unaffected.
  • A test asserts the exported path for a header and a non-header document in both C and C++.

Activity

  1. added
    bug
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions