Why explicit cast?

Chris Miller chris at dprogramming.com
Sun Feb 11 14:22:18 PST 2007


On Sun, 11 Feb 2007 17:08:41 -0500, Andreas Kochenburger <akk at nospam.org>  
wrote:

> I find it extremely annoying to have to write 'cast' before every C-like  
>   cast. The C-syntax is as clear as tap water, so why had this  
> complication been added?

It's ambiguous, (a)-b is a cast or subtraction.

cast() jumps out at you, you know exactly what a cast is. I remember  
digging through 'h' files before and wondering what the heck a #define was  
doing, to realize a minute later that it was a cast; it's not always  
obvious, especially if it doesn't use spacing you're used to.

Casting shouldn't be done that much, so it's a bit inconvenient, and  
explicitly warns readers of the code what it's doing. However, it's not  
"too" inconvenient; this argument rarely pops up.

And last, as the other reply mentioned, you can search for it easily.

- Chris



More information about the Digitalmars-d-announce mailing list