SGDK and C++

SGDK only sub forum

Moderator: Stef

Post Reply
Cyttorak
Newbie
Posts: 3
Joined: Fri Feb 10, 2012 11:19 am

SGDK and C++

Post by Cyttorak » Fri Feb 10, 2012 11:20 am

Hi!

I recently discovered that great toolset called SGDK. My question is: can I use C++ with SGDK instead of plain C?

Thanks in advance :)

SoullessSentinel
Interested
Posts: 24
Joined: Wed Feb 03, 2010 12:53 am
Location: Grimsby, England

Post by SoullessSentinel » Fri Feb 10, 2012 1:04 pm

I haven't checked if the SGDK contains a C++ compiler as well as the C compiler, however, even if it does, I highly recommend using plain C over C++.

One of many reasons, being the MegaDrive only contains 64KB RAM for variables (and in C++, objects), and under normal means you only have 4MB of ROM space to work with, which needs to contain all your code and data as well as the C/C++ runtimes.

Because of these limitations, the small overhead of C++ has more of an impact on here than on PC platforms, and you'd have less space to work with as a result.

Someone more knowledgeable on the toolchain could give you a better answer, as I use Assembly instead of C, but I think many people will agree that on low end platforms, the overhead of C++ isn't really worth it.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Feb 10, 2012 7:07 pm

My own MD/32X toolchain has both C and C++ compilers and examples for both. You'd probably have to make some changes to SGDK to make it work in C++, namely wrapping the functions in the h files and making new makefiles. In any case, I've found C++ isn't THAT bad on the MD, just avoid <iostream> since that's where the worst bloat comes in (makes a program go from 8K to 400K).

SoullessSentinel
Interested
Posts: 24
Joined: Wed Feb 03, 2010 12:53 am
Location: Grimsby, England

Post by SoullessSentinel » Fri Feb 10, 2012 7:15 pm

Do you have a Windows build of your toolchain? Or will I have to compile myself in Cygwin? I wasn't expecting the overhead to be that little ,so, I wouldn't mind giving it a try myself.

Cyttorak
Newbie
Posts: 3
Joined: Fri Feb 10, 2012 11:19 am

Post by Cyttorak » Fri Feb 10, 2012 7:17 pm

Thanks for your help guys.

I don't think C++ will be so heavy on MD. You just need to avoid iostream, as you said, and also some things like RTTI or exceptions. I would be glad to hear your own experiments on C++ tests on MD :)

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri Feb 10, 2012 9:24 pm

At least SGDK doesn't include it by default, because C++ compiler requires many more stuff to work correctly, and because i believe the C++ overhead makes it not really interesting (not necessary on performance, but more on RAM usage).
Anyway i guess it can be interesting in almost case anyway, just avoid it when you need performance or max memory =)
Last edited by Stef on Fri Feb 10, 2012 9:28 pm, edited 1 time in total.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Feb 10, 2012 9:26 pm

SoullessSentinel wrote:Do you have a Windows build of your toolchain? Or will I have to compile myself in Cygwin?
I do my dev'ing in Xubuntu, so no, I don't have a Windows build. Others have reported that they could follow my directions using mingw in Windows:

viewtopic.php?p=12858#12858

on the plus side, once you figure out how to build it yourself from my directions, it becomes easy to update/maintain your toolchain yourself instead of needing to wait for someone to make an update. 8)

That was why I worked it out myself - I got tired of needing to rely on the uClinux m68k compiler, which hadn't been updated in a LONG time.

I wasn't expecting the overhead to be that little ,so, I wouldn't mind giving it a try myself.
Working from the PD sources (I combined three different PD TicTacToe sources along with my own changes to make the examples), the overhead was HUGE... until I commented out iostream (since I no longer used cin/cout for the game), then it dropped to darn near the same size of the C version of the example. This main problem with C++ and size on the MD is the linker cannot trace what may or may not be used because of the binary header at the start of the file, so it links in EVERYTHING out of the libs you use... tell it that you might use part of iostream and you get the WHOLE THING. So you have to watch what you include, but otherwise I had no troubles with C++. I need to work on a larger C++ project to get a REAL idea of how it does on the MD/32X.

Cyttorak
Newbie
Posts: 3
Joined: Fri Feb 10, 2012 11:19 am

Post by Cyttorak » Mon Feb 13, 2012 11:22 am

Chilly Willy wrote:
SoullessSentinel wrote:Do you have a Windows build of your toolchain? Or will I have to compile myself in Cygwin?
I do my dev'ing in Xubuntu, so no, I don't have a Windows build. Others have reported that they could follow my directions using mingw in Windows:

viewtopic.php?p=12858#12858

on the plus side, once you figure out how to build it yourself from my directions, it becomes easy to update/maintain your toolchain yourself instead of needing to wait for someone to make an update. 8)

That was why I worked it out myself - I got tired of needing to rely on the uClinux m68k compiler, which hadn't been updated in a LONG time.

I wasn't expecting the overhead to be that little ,so, I wouldn't mind giving it a try myself.
Working from the PD sources (I combined three different PD TicTacToe sources along with my own changes to make the examples), the overhead was HUGE... until I commented out iostream (since I no longer used cin/cout for the game), then it dropped to darn near the same size of the C version of the example. This main problem with C++ and size on the MD is the linker cannot trace what may or may not be used because of the binary header at the start of the file, so it links in EVERYTHING out of the libs you use... tell it that you might use part of iostream and you get the WHOLE THING. So you have to watch what you include, but otherwise I had no troubles with C++. I need to work on a larger C++ project to get a REAL idea of how it does on the MD/32X.
Very interesting, Chilly. Do you have any experience in this context with STL? Perhaps with template system linker is able to link only what you use

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Feb 13, 2012 5:15 pm

From my experience, it can't figure out what is used and what is dead code because of the special binary headers used with the MD/32X. That causes it to just include EVERYTHING from the libs used rather than just what actually is used.

Post Reply