GP32 new operator


mak

Still Fresh
Joined
Aug 7, 2003
Messages
18
Website
www.maksw.com
No C vs C++ arguments please ;)

Has anyone attempted using C++ classes on the gp32?

I've implemented my GBA framework quite successfully (which in fact is about 4.74 times better than it could be on the gba ;) ). But, when attempting to use the new operator, I either get "undefined reference" when linking, or, it links ok, but crashes when invoked.

I assume the devkitadv does not support "new", which is odd, as I used new extensively on the gba. :blink:

Anyone got any ideas? Or has anyone ever implemented their own "new" functionality? :ph34r:

Thanks in advance...
 
I don't use devkitadv, but have you checked some simple things, like making sure you're using the c++ compiler, and linking to libstdc++?
 
well, i'm only using C++.
You have to make sure that you link with libstdc++ (add -lstdc++ to the linker line).
But new would probably use malloc() in the end, which is a bad thing, since the SDK uses gm_malloc(), thats why it's a good idea to overload the new operator and use gm_malloc instead.

void* operator new(long unsigned int sz)
{
return gm_malloc(sz);
}

---
mithris
 
I am using the right dev env etc - I test my code in geepee32 first, and then move it to gp32 hardware later.

And I am linking libstdc++ (with the linker option -lstdc++ )

Hmm ok - confused a little - still don't know why it works on some and not on others.

Ok - mithris - could you expand on your overide of new for me? I understand what you mean, but have never attempted it :ph34r: , and it looks like you have ;)

I would want to do both the following :-

CObject* pObj = new CObject ;
and
CObject* pObj = new CObject[20] ;
 
Back
Top