This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Checked casts in CNI


>>>>> "Bryce" == Bryce McKinlay <mckinlay@redhat.com> writes:

Bryce> I think this is a good idea, although it would be even nicer if we
Bryce> could make it use the C++-style casting syntax. For example:
Bryce> addr = java_cast<::java::net::InetAddress> (value);

I've considered in the past using 'dynamic_cast<>' for this, but I
wonder whether the g++ maintainers would accept that.
Yours is easy though :-).  (Though I didn't actually test it or anything)

template<typename T, typename S>
inline T
java_cast (S value)
{
  return reinterpret_cast<T *> (_Jv_CheckCast (&T::class$, value));
}

This is a little peculiar since the template type argument is the
class and not a pointer to the class.

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]