gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > full C++ features

#18526 - ns2v - Sun Mar 28, 2004 2:21 pm

hello,

i'm trying to have clean C++ support on gba. But i still have two problems.
First, i need to call myself the globals constructors from a list build with the linkscript. Second, exceptions works only if i use catch ( ... ), with a catch ( type t ), the execution freeze on the throw.

If you have ideas, specially for the first problem, because i don't like the way i call the constructors manually.

thanks,
ns2v.

#18527 - Paul Shirley - Sun Mar 28, 2004 2:39 pm

removed

Last edited by Paul Shirley on Sun Mar 28, 2004 8:54 pm; edited 1 time in total

#18528 - beelzebub - Sun Mar 28, 2004 2:50 pm

Constructures are called by the startup code (usally ct0.s), but if you're using a home grown version, or one from somebody who only uses striaght C, the chances are the list of constructures (and destructors) is not being called.

somelike this is needed in crt0.s

Code:

   .extern   __CTORS_START,__CTORS_END
   .extern   __DTORS_START,__DTORS_END
      .CODE   32
      .ALIGN
      .GLOBAL   __gccmain
__gccmain:
__main:
   @ Handle C++ constructors
      ldr      r8,=__CTORS_START
      ldr      r9,=__CTORS_END
handle_tors:
      mov      r11,lr
tors_loop:
      cmp      r8,r9
      bxge   r11
      ldr      lr,=tors_loop
      ldr      r0,[r8],#4
      bx      r0


is gccmain is called by the compiler at the start of main().

#18529 - ns2v - Sun Mar 28, 2004 3:04 pm

it's exactly what i did but in c style for the moment. And yes my crt0 is homebrew because i do some initialisation process and interrupt code here. So, you think it's normal. I thank that was not the case because i read somewhere that in c++ mode, gcc identify the call to main and insert the __gccmain at this point.

Remain my exception problem now.