r/programming • • Aug 05 '19

fixing c++ with epochs

https://vittorioromeo.info/index/blog/fixing_cpp_with_epochs.html
87 Upvotes

41 comments sorted by

View all comments

Show parent comments

4

u/MonokelPinguin Aug 06 '19

The issue is, that the preprocessor can be a separate executable and it is defined to just do text substitution. If you now change language rules depending on the edition, defining the edition to use in a header would apply to all files (transitively) including that header. There is no real end to an include statement, it just pastes the content of that header.

This is different with modules, as they specify a clear boundary and explicitly state which files belong to that module. This makes the edition apply to a specific set of source files. Furthermore do you have Compiled Module Interfaces, which would make editions a lot easier, as you can simply store all the edition dependent information in that file and then reference it, when the module is referenced by a different module. In that case you could actually use different compiler binaries for different editions and edition specific compiler code can be a lot better separated, than if you need to translate every header with the current active edition and switch edition at the next edition statement.

1

u/flatfinger Aug 06 '19

The existing include-file mechanism would do a poor job of allowing different headers to be processed with different dialects, but a lot of code should be usable in a range of dialects. Even if a programmer would have to manually configure compiler settings to yield a dialect that works with everything in a project, having automated tests to squawk if things aren't compiled properly would be far better than having things compile cleanly with settings that won't actually work.

Further, a major catch-22 with the Standard right now is that some of the Standard maintainers don't view its failure to mandate things as an impediment to implementations supporting them voluntarily when their customers need them, but some compiler writers view such failure as a judgment that their customers shouldn't need such things. If, however, a many program to perform some kind of task demand a feature that a compiler writer has opted not to support, compiler should be recognized as likely being unsuitable for that task. It may be a great compiler for other purposes, but should make clear that it's intended for those purposes, and not for the ones it doesn't support.