Constexpr-8cc: Compile-time C Compiler
github.com
github.com
Lightweight Modular Staging (Scala): https://scala-lms.github.io/
Terra (Lua): http://terralang.org/
Compiler Plugins (Rust): https://doc.rust-lang.org/book/compiler-plugins.html
The amount of investment in the language is astounding. It's only going to continue to expand.
The last useful change in C++ was (circa 2006?) making string literals const. That's it.
What about: lambdas, type inference, tuples, robust templates, compile time constants and code execution, move semantics, expanded PoD, initializer lists, range based for loops, user literals, return type deduction... I could go on and on. All features I use daily. And I'm not even getting into C++17.
> And I'm not even getting into C++17.
I'm with you there, in a way.
What you're suggesting is tantamount to throwing out C++'s current syntax, which will never happen, or taking the existing parser and making it even more complicated so that it supports extensions.
28374 /* Commit to the currently active tentative parse. */
28375
28376 static void
28377 cp_parser_commit_to_tentative_parse (cp_parser* parser)
28378 {
28379 cp_parser_context *context;
28380 cp_lexer *lexer;
28381
28382 /* Mark all of the levels as committed. */
28383 lexer = parser->lexer;
28384 for (context = parser->context; context->next; context = context->next)
28385 {
28386 if (context->status == CP_PARSER_STATUS_KIND_COMMITTED)
28387 break;
28388 context->status = CP_PARSER_STATUS_KIND_COMMITTED;
28389 while (!cp_lexer_saving_tokens (lexer))
28390 lexer = lexer->next;
28391 cp_lexer_commit_tokens (lexer);
28392 }
28393 }
Bison supports GLR ("generalized LR") via some technique of forking the parser and trying alternatives in parallel, which seems related to this. template<bool> struct a_t;
template<> struct a_t<true> {
template<int> struct b {};
};
template<> struct a_t<false> {
enum { b };
};
typedef a_t<sizeof(void*)==sizeof(int)> a;
enum { c, d };
int main() {
a::b<c>d; // declaration or expression?
}
It's a fun C++ IDE torture test, which few pass. One that does is Visual Studio - if you create a C++ project and set up both 32-bit and 64-bit build targets, you can flip between them, and see the syntax highlighting change on the line with the comment.Rust seems like a promising alternative in the future.
Agreed, but, sometimes people need to do stuff RFN. And sometimes that doesn't leave time for learning new things, even if they might be somewhat better.
And edit to add that I think rust, in particular, is doing some very interesting things to hugely reduce the learning curve and make it a better language for newcomers.
I used to despise C++, but ever since I've had to abandon all usage of it's std library, I don't mind it anymore. It's a bit less crufty that way. Though I'm still peeved every time the compiler dumps 30 pages of every virtual method in existence because it couldn't find one that matched my call.
C++ turned out kinda... good -- considering that it started out as "tacking classes on C".
You are bound, then, "to reimplement it, poorly."
A recent update on the compile time function execution is here http://dlang.org/blog/2016/11/18/project-highlight-the-new-c...
According to TIOBE [1] D is more popular than Rust (21 vs 43 in the rankings). Of corse ranking language popularity is a tricky task, so ymmv.
It doesn't guarantee that.
For example:
static constexpr int fac(int x) { return x <= 1 ? 1 : x * fac(x - 1); }
int f() {
return fac(4); // May or may not be evaluated at run-time.
}
char arr[fac(4)]; // fac(4) is evaluated at compile-time.I wonder how long it will take before C++ accidentally becomes a Lisp.
(Compiling C is mostly out the window now of course)
:)
The reason I mentioned it is that some of the syntactic horrors of C++ could safely be thrown out the window these days.
BTW though I'm primarily still a Lisp programmer I do like C++
My current hobby project is a language VM that compiles cleanly as both C and C++. It took very little effort to get it working in C++ despite hacking on it for months as a strictly C project first.
int *new = malloc(sizeof(int));
is valid C but invalid C++ for two different reasons: "new" is a keyword in C++, so you can't use it as an identifier, and C++ doesn't allow implicit casts from void*, while C does.Hope this helps.
Machine generated vimscript.. so gross