On Saturday, 11 January 2025 at 23:31:14 UTC, Walter Bright wrote:
>I am suspicious that mandating CTFE in C standard would be a good idea. C is full of all sorts of undefined behaviour even in pure functions, and it'd be a security disaster if executing undefined behaviour at compile time would also be undefined behaviour. Also consider cross-compiling: the function might be different in the host and the target platform. This means it'd be quite complex to specify and implement.
Don't get me wrong, I think CTFE is a great idea. But C is intentionally only adding relatively small evolutionary changes. CTFE wouldn't fit that very well, especially since it'd be relatively limited in C thanks to lack of the garbage collector.
As for lack of forward declarations, maybe they want to avoid two different C standards compiling with different semantics.
float foo(){ return 10.0 + bar(); }
float bar(void);
I believe this would compile in C90, but with bar()
in foo()
"returning" an int
and therefore probably corrupting the stack.