Treating the abusive unsigned syndrome

Tomas Lindquist Olsen tomas at famolsen.dk
Wed Nov 26 16:44:40 PST 2008


I'm not really sure what I think about all this. I try to always insert 
assertions before operations like this, which makes me think the nicest 
solution would be if the compiler errors out if it detects a problematic 
expression that is unchecked...

uint diff(uint begin, uint end)
{
	return end - begin; // error
}


uint diff(uint begin, uint end)
{
	assert(begin <= end);
	return end - begin; // ok because of the assert
}


I'm not going to get into how this would be implemented in the compiler, 
  but it sure would be sweet :)



More information about the Digitalmars-d mailing list