Isn't the C++ "reference" annotation

  char & x;

tantamount to declaration of a pointer

  char * x;

to whom NULL assignment, as detectable at compile time, is a compile-time error?

If so, is that adequately applicable?

________________________________________
From: webkit-dev-boun...@lists.webkit.org [webkit-dev-boun...@lists.webkit.org] 
On Behalf Of Maciej Stachowiak [...@apple.com]
Sent: Tuesday, July 28, 2009 4:19 PM
To: Peter Kasting
Cc: WebKit Development
Subject: Re: [webkit-dev] NeverNull<T>

On Jul 28, 2009, at 3:59 PM, Peter Kasting wrote:

On Tue, Jul 28, 2009 at 3:55 PM, Oliver Hunt 
<oli...@apple.com<mailto:oli...@apple.com>> wrote:
Personally i like the idea of having type system/compiler enforced null 
checking.

Note that eseidel's proposal is still a runtime check.  One could use template 
specialization to write a class that gives a compile-time error if you try to 
assign NULL directly to a pointer, but I'm not enough of a template wizard to 
know if it could be made to catch all types of assignment (e.g. if you could 
catch that when a NeverNull<Foo> is initialized by an existing Foo*, that 
existing pointer must not contain NULL).

I don't think you can make the C++ type system prevent pointers from having 
null values without a runtime check. Any raw pointer expression could have a 
null value and this is not visible at compile time. It might be possible to 
prevent direct assignment of 0, which would provide at least a little bit of 
static checking.

Regards,
Maciej

_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to