This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: C++ and Java CNI: Check Java references
- To: mharrold at cas dot org
- Subject: Re: C++ and Java CNI: Check Java references
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Wed, 25 Apr 2001 11:56:45 -0700
- Cc: tromey at redhat dot com, aph at redhat dot com, rth at redhat dot com, per at bothner dot com, java at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <20010425101504Q.mitchell@codesourcery.com><200104251847.OAA06078@mah21awu.cas.org>
>>>>> "Mike" == Mike Harrold <mharrold@cas.org> writes:
Mike> only thing the compiler knows is that references SHOULD
Mike> never be NULL.
The point is that the compiler can assume references are never NULL
and optimize accordingly.
If you break the rules, the compiler may or may not generate code that
behaves like you expect. For example, if you write:
void h(X& x) {
if (&x == 0) f();
else g();
}
The compiler may just turn this into:
void h(X& x) {
g();
}
If you expect `f' to be called when you pass `h' something like:
`*((X*) 0)', you will be disappointed.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com