SGDK and C++
Moderator: Stef
SGDK and C++
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
I recently discovered that great toolset called SGDK. My question is: can I use C++ with SGDK instead of plain C?
Thanks in advance
-
- Interested
- Posts: 24
- Joined: Wed Feb 03, 2010 12:53 am
- Location: Grimsby, England
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.
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.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 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).
-
- Interested
- Posts: 24
- Joined: Wed Feb 03, 2010 12:53 am
- Location: Grimsby, England
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
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 =)
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.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm
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:SoullessSentinel wrote:Do you have a Windows build of your toolchain? Or will I have to compile myself in Cygwin?
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.
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.
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.I wasn't expecting the overhead to be that little ,so, I wouldn't mind giving it a try myself.
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 useChilly Willy wrote: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:SoullessSentinel wrote:Do you have a Windows build of your toolchain? Or will I have to compile myself in Cygwin?
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.
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.
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.I wasn't expecting the overhead to be that little ,so, I wouldn't mind giving it a try myself.
-
- Very interested
- Posts: 2984
- Joined: Fri Aug 17, 2007 9:33 pm