Integration with C
gbevin@uwyn.com
gbevin@uwyn.com
Tue Apr 22 09:34:00 GMT 2003
Hi Andrew,
> > I see how this would work, but my main question is how do you get the
> > function point in the method variable. Here you only use it, you never
> > provide it. Since the interface needs to be declared in java as being
> > native, there's no way to write a method that takes a function pointer
> > argument, is there?
>> I'm totally mystified by where you think the problem might be.
> Declare a Java native method that takes a RawData arg, and cast a
> function pointer to RawData. It's not legal C++, but it will work on
> many architectures.
Ok, that's what I did, but I was in fact just wondering if it was doable
by providing an interface that's valid to use in c++ without taking gcj
into account. Ie. don't having to explain to regular c++ users that they
need to cast to RawData and such.
> > Would it be possible to derive the Callback class in C++ alone and
> > add a setCallback(fptr callback) method?
>> Sure, why not? You can write all of a Java class's implementation in
> C++ if you wish.
The question is not if I can implement a Java class completely in c++,
but if it's valid to derive a Java class and create a class in c++ alone
(without a java counterpart). This derived class could then provide an
api where the methods contain correctly typed arguments so that the
users of the class don't have to cast to RawData all the time. Tom
hinted that this would in fact not be possible.
> Perhaps, but it is legal C++, and casting function pointers to data
> pointers isn't.
>> You lose no typed information by doing this. Declare the array of
> function pointers with the correct type.
Thanks for the info !
Take care,
Geert
--
Geert Bevin Uwyn
"Use what you need" Lambermontlaan 148
http://www.uwyn.com 1030 Brussels
gbevin[remove] at uwyn dot com Tel & Fax +32 2 245 41 06
PGP Fingerprint : 4E21 6399 CD9E A384 6619 719A C8F4 D40D 309F D6A9
Public PGP key : available at servers pgp.mit.edu, wwwkeys.pgp.net
More information about the Java
mailing list