Obvious Things C Should Do

Dukc ajieskola at gmail.com
Tue Jan 28 12:38:25 UTC 2025


On Thursday, 23 January 2025 at 16:20:21 UTC, Quirin Schroll 
wrote:
> On Monday, 13 January 2025 at 16:13:10 UTC, Dukc wrote:
>>> D's CTFE does not allow undefined behavior.
>>
>> It's pretty simple in D since it has the @safe subset where 
>> everything is defined behaviour anyway.
>
> That’s simply wrong. `@safe` code can call `@trusted` code and 
> that can execute undefined behavior if it has a bug.

Yes, if we're precise about it.

It doesn't contradict what I meant though. Since D has `@safe`, 
things like overflows, uninitialised variables, underflows, 
attempting to modify a string literal etc. have to be defined 
behaviour. The C standard mostly handles these by saying 
"Undefined behaviour. Just don't do it." but the D spec can't, 
otherwise `@safe` wouldn't do what it's supposed to, CTFE or no.

Because of that, the D spec doesn't require a lot of paper to 
accomodate for CTFE, but it would require a big overhaul of the C 
spec unless it can allow compile-time undefined behaviour somehow.


More information about the Digitalmars-d mailing list