This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Null pointer check elimination
- From: Diego Novillo <dnovillo at redhat dot com>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: Per Bothner <per at bothner dot com>, gcc at gcc dot gnu dot org, Anthony Green <green at redhat dot com>, java at gcc dot gnu dot org
- Date: Sat, 12 Nov 2005 13:52:53 -0500
- Subject: Re: Null pointer check elimination
- References: <1131747852.3205.105.camel@localhost.localdomain> <200511121239.23599.dnovillo@redhat.com> <m3slu1ww6l.fsf@uniton.integrable-solutions.net>
On Saturday 12 November 2005 13:36, Gabriel Dos Reis wrote:
> I'm not convinced. I believe Per's suggestion is far superior, and
> more general and does cover pretty well the issue at hand. Plus,
> a pointer-type-without-null is another spelling for reference type.
>
I'm thinking of C here, where we don't have that luxury. The original RFE
was in 20318 where they have some C functions that are guaranteed to
return non-NULL (I'm quoting from memory here):
int *this_never_returns_NULL (void) __attribute__ ((never_returns_null));
We would not want to pin the never-null attribute to 'int *':
foo()
{
int *p = this_never_returns_NULL ();
< ... use p without modifying it ... > <-- p is never NULL here.
p = other_fn ();
< ... use p without modifying it ... > <-- p may be NULL here.
}
In languages where you could make the type itself have that guarantee, then
great, let's use the type attributes. In type-challenged languages, we
use whatever we can get our hands on.