DaemonSnake / single-header

a rust command line utility to generate portable C/C++ single header file
MIT License
7 stars 0 forks source link

multiple translation unit safety #5

Open DaemonSnake opened 7 months ago

DaemonSnake commented 7 months ago

If the input file contains non-inlined declaration the resulting header will cause ODR violations if included in multiple files.

As we are still before the preprocessing step we don't have valid C++ yet so parsing and adding the inline keywords where needed could work but the parser will likely fail.

If we had something like scoped qualifiers (inline { ... }) that would be trivial to fix.

Putting all the root level code (not included) in an anonymous namespace was also considered but won't do. Method definitions after declarations won't compile if put in an anonymous namespace.

DaemonSnake commented 7 months ago

Looked around for solutions found by other tools. One of the simplest solution implementation wise (but the worse for the end user) is the use of implicitly declared macros. Really dislike this option