A couple of thoughts/queries.

James Dennett jdennett at acm.org
Mon Dec 24 18:30:20 PST 2007


Walter Bright wrote:
> Robby wrote:
>> Anyways, what I'm in hopes of finding is a way to tell the compiler
>> that I never want null, ever. I want an instance of the class and
>> that's that. The whole idea of taking every lil runtime hit for
>> checking  and the code cruft for writing it when in fact it's
>> something that seems to be easy for a compiler to do the work for me.
> 
> The hardware will do the check for null pointer for you every time you
> do a dereference.

Often, yes, but not always.  Presumably compilers are smart enough
*not* to count on this for large offsets into objects and add explicit
code when they guarantee to diagnose dereferences from null pointers.
(But I'd check the generated code if I was going to rely on such a
thing instead of ensuring that it didn't happen in the first place.)

-- James



More information about the Digitalmars-d mailing list