D2.0: an example of use-case for casting invariant away

Jason House jason.james.house at gmail.com
Sun Jun 24 11:37:23 PDT 2007


James Dennett wrote:
> Jason House wrote:
>> Don Clugston wrote:
>>> int* d = cast(break const) b;
>>>
>>> IMHO, we want something that looks really nasty.
>> Based on all the discussion in this thread, I like this alternative
>> best.  I'd only insist that if someone did int *d = cast(int*) b; that
>> the compiler would issue an error saying to use cast(break const) instead
> 
> Interesting: my experience suggests that it shouldn't do so.
> Those who know enough to use cast(break const) appropriately
> will find out how to do so.  Others would just read the error
> message and blindly do what it said, pausing only briefly to
> wonder why the compiler issued an error message if it knew
> exactly how to "fix" the code.  Far too many programmers'
> first reaction to type warnings/errors is to add casts and
> mask the problem rather than addressing root cause.
> 
> -- James

... And what about those programmers who know what they're doing but 
don't know the ins and outs of the language perfectly?  Should they 
start scouring the documentation and news groups to find the proper fix?

IMHO, error messages should be as helpful as possible.  Besides giving a 
new syntax with "break const" embedded within it.  I don't think there's 
really anything else we can do to stop crazy programmers who'll do 
anything to get their code to function.  D has many cool features that 
attracted me to use it, but I'm already near my limit of frustration 
using such a volatile language.

PS: How do you fix a large program that gives just this one compilation 
error (with gdc after compiling and running perfectly with dmd):
/include/d/4.1.1/std/traits.d:134: Error: void initializer has no value

$ head -n 134 /include/d/4.1.1/std/traits.d | tail -n 3
template isStaticArray_impl(T)
{
     const T inst = void;



More information about the Digitalmars-d mailing list