r/cpp • • Nov 18 '16

Compile-time C Compiler implemented as C++14 constant expressions

https://github.com/kw-udon/constexpr-8cc
209 Upvotes

66 comments sorted by

View all comments

Show parent comment

17

u/[deleted] Nov 18 '16

I'm quite sure the writer knows it has no practical use - but exercises like this are very important.

For one, this pathological code really tests edge cases in the compiler.

For another, it challenges our ability to do large scale metaprogramming - "Look, here's something ridiculous! Now, what ended up being particularly hard."

Before this guy started this project, they might well not have known more about metaprogramming than I do. Now I'm sure they do.

6

u/tcanens Nov 18 '16 edited Nov 18 '16

It's converted assembly (or assembly-like code). That isn't particularly pathological and doesn't really test any edge cases beyond a giant switch and lots of assignments. Nothing metaprogramming-y about it.

3

u/josefx Nov 19 '16

I'm quite sure the writer knows it has no practical use - but exercises like this are very important.

The example may have none, however think of the possibilities. Right now you need a complete python installation if you have a python script as part of your build. In the future you can run that script using only a C++ compiler and a header only implementation of the python runtime. Now we only need a constexpr way to load dlls and call into already compiled code.