assert(0) behavior

via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 3 20:37:29 PDT 2015


On Tuesday, 4 August 2015 at 03:04:14 UTC, Dicebot wrote:
> indeed. I remember Iain complaining about presence of HLT (and 
> saying he won't do that for gdc) for exactly this reason.

Yes. I think a lot of this confusion could have been avoided by 
using "halt()" instead of "assert(0)" and "unreachable()" for 
marking code that has been proven unreachable. Right now it isn't 
obvious to me as a programmer what would happen for 
"assert(x-x)". I would have to look it up.

A more principled approach would be:

- "enforce(...)" test for errors

- "assert(...)" are (lint-like) annotations that don't affect 
normal execution, but can be requested to be dynamically tested.

- "halt()" marks sudden termination

- "unreachable()" injects a proven assumption into the deductive 
database

-"assume(...)" injects a proven assumption into the deductive 
database

- contracts define interfaces between separate pieces of code 
(like a plugin or dynamically linked library from multiple 
vendors e.g. sub system interface) that you may turn on/off based 
on what you interface with.

The input/environment/code distinction does not work very well. 
Sometimes input is a well defined part of the system, sometimes 
input is code (like dynamic linking a plugin), etc...



More information about the Digitalmars-d mailing list