[Verse-dev] Using tags and C++ issues

Emil Brink emil at obsession.se
Tue Apr 26 09:11:18 CEST 2005


On Mon, 25 Apr 2005 15:12:05 +0300 (EEST)
Samuel Siltanen <saasilta at cc.hut.fi> wrote:

> On Mon, 25 Apr 2005, Emil Brink wrote:
> 
> > Do you have to compile the Verse core code as C++, too? If you
> > compile it separately as C and link to the library, isn't the number
> > of such problems reduced?
> 
> Yes, it would be, but unfortunatelly it is not possible with the
> compiler  I use. I get those same "undefined references" which TJay
> mentioned  earlier. This problem has nothing to do with Verse, but the
> fact that  the object files generated by gcc and g++ do not work
> together.

Like Brecht already pointed out, that should not be true. And especially
so with the (recommended) release-r5-branch that is soon-to-be-R5. It
has the required declarations in place in verse.h, and works just fine
to link to a C++ program.

Anecdotal "proof":

--------------->8--------------------------------------------------------

~/data/src> cat verse++.cpp 
#include <iostream>
#include "verse.h"

using namespace std;

static void cb_connect_accept(void *user, VNodeID node_id,
			      void *address, void *connection,
			      const uint8 host_id)
{
        cout << "Connected, yeah!\n";
}

int main()
{
        verse_callback_set((void *) verse_send_connect_accept,
		          (void *) cb_connect_accept, NULL);
}
~/data/src> g++ -I../projects/verse verse++.cpp  -L../projects/verse -lverse
~/data/src> 

--------------->8--------------------------------------------------------

So, as you can see it's perfectly possible to compile C++ program and
link it against the pre-compiled (as C) libverse.a library, using the
same tools you are using. This is on a Linux system, with GCC 3.3.5.

> > I don't have a good solution for the callback function pointer
> > types, at the moment. There is no way (that I know) to express
> > "pointer to function that takes an unknown number of arguments" in
> > C, without making it into a varargs function. Tips are very welcome.
> 
> I cannot imagine a way of doing it in C either. Of course it would be 
> possible to do something like:
> 
> #ifdef __cplusplus
>     // The code with C++ casting
> #else
>     // The C code version with (void *)
> #endif
> 
> But this is very ugly.

Yes, and changing the *insides* of Verse to better accomodate C++ is
not required, so I'm not focusing on that. The code above has a couple
of ugly casts to void * for the callback_set() arguments, true, but
that should more or less be all that is needed. I experiemented with
other declarations of verse_callback_set() yesterday, but couldn't find
a solution.

Um, I realize those casts should probably be done in a more C++-ish
style, but my C++ is slightly rusty... Is it static_cast<void *> I
mean?

> > Absolutely. To be honest, I haven't built a C++ program using Verse
> > my- self, but am aware of there being issues. Camilla, who works
> > here at KTH, has done some work on a C++ wrapper (Ample), but I'm
> > not sure what the status is there.
> 
> I am aware of that (it is in CVS), but I have not get it work yet.

Okay... I wish I could help you out there, but I haven't gotten around
to looking into Ample yet. :/

[...]
> > Just as a ballpark figure, could you say how many tag values we're
> > talking about here?
> 
> At first a tested with 10000-20000 values, but because that did not
> work,  I used about 20 of them, but still I got only a fraction of
> them back.

Aha, that is indeed "many" values. :) Tag IDs (both group and tag) are
16-bit, so there are limits for this approach. If at all possible, it
would be interesting to use the material system, but I remember from
discussions with Lauri & Peter that it's not very well suited since it
deals strictly with 3D (RGB) data, and for material audio properties
you need more frequency bands. Perhaps this could be done by just using
several trees in parallel, though.

The tags-disappear problem is suspect, I will try to find the time
today to do a small test of the issue by just creating a lot of tags
and then subscribing to them. Thanks for pointing it out, more later.

Regards,

/Emil


More information about the Verse-dev mailing list