3 ms·
Any plans to add semantics for exceptional situations such as divide by zero and dereferencing a null pointer? https://blog.regehr.org/archives/232 https://blog
by potiuper 7y ago
Any plans to add semantics for exceptional situations such as divide by zero and dereferencing a null pointer? https://blog.regehr.org/archives/232 https://blog.regehr.org/archives/232
Or incorporating features from this 14 item list? https://blog.regehr.org/archives/1180 https://blog.regehr.org/archives/1180
As it appears these have failed: https://blog.regehr.org/archives/1287 https://blog.regehr.org/archives/1287
- DougGwyn 7y agoThe problem is that if the checks are always performed, the object code is significantly slowed down. If all computers supported the checking in hardware, then we could do it. You don't really want the current C approach (signal) to trigger except in an emergency, because there is no way to insert cleanup/retry/etc. recovery code via a signal handler.
- rseacord 7y agoI don't know of any plans to add semantics for divide-by-zero of dereferencing a null pointer. I'm guessing this is not viable because there is no agreed upon semantics among different implementations. Making C friendlier is always a good idea, and I think the committee is (slowly) working towards this goal. I would have to examine these papers by John Regehr in more detail. Looking quickly at his proposals I can see why there he couldn't find consensus for these ideas as some of them do appear controversial. An example of a friendly dialect of C is always is C0 (C-naught) from CMU. I don't think I'm exaggerating when I say that this language has not "caught on".
- flatfinger 7y agoConsider the following function: int test(int a, int b) { int c = a/b; if (f1()) f2(a,b,c); } Should a compiler be required to compute c before calling f1, and thus have to store the value of c across the function call? Better would be to define a set of semantics for loosely-sequenced traps, along with "causality barriers" to ensure that they only occur at tolerable times.