C++ exceptions

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
RyoDC
Mental DCEmu
Mental DCEmu
Posts: 366
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Mar 30, 2011 12:13 pm
Has thanked: 2 times
Been thanked: 0

C++ exceptions

Post by RyoDC »

Are they supported by KOS?
Should I use them or should I avoid their usage?

P.S. Some interesting discussion on the topic: http://stackoverflow.com/questions/2226 ... ons-or-not
How do I try to build a Dreamcast toolchain:
Image
User avatar
PH3NOM
DC Developer
DC Developer
Posts: 576
Joined: Fri Jun 18, 2010 9:29 pm
Has thanked: 0
Been thanked: 5 times

Re: C++ exceptions

Post by PH3NOM »

I have not used C++ very much on the DC, in fact, the only project I worked on in C++ was the Kamikaze demo I wrote to test compiling C++ against my C build of GL viewtopic.php?f=29&t=102328&view=next#p1034678

KOS handled all of the C++ features I implemented just fine, although I admit I did not use any try/catch exception handling in any of my classes, I would dare to guess KOS handles that just fine.

But every class I wrote for school that required exception handling, I always thought of other ways to prevent the exception from happening to prevent needing to handle it in the first place.

I think someone mentions in one of the posts in the thread you linked to that C++ is typically best to stay away from when working on an embeded device with greatly limited resources compared to a modern PC.
That is pretty much why most of the KOS examples are written in C, not C++.

But as BlueCrab would profess, if you really want optimized code, you will need to learn assembly, as our friend TapamN has enlightened some of us with vast knowledge of compiler-level code optimization / hand written SH4 assembly.

In the end, what it comes down to is what you are actually doing.
Your question is a bit too general to determine weather or not C++ exception handling should be invoked in the classes you are working on...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5666
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: C++ exceptions

Post by BlueCrab »

The last time I tried to use C++ exceptions, they worked. However, KOS' default C++ flags disable exceptions and rtti, so you'll have to change them. However, your milage may vary, and they may well not work. I know that it was the case at least some time in the past that they did not work.

Simply put, you should try to avoid them anyway since they do tend to lead to inefficient code. If you can't, minimize their use. I'd also suggest minimizing dependence on OOP (so pretty much all C++ features) in general, since once again, it tends to lead to inefficient code. Neither exceptions nor OOP cause inherently inefficient code, but they do tend to lead people to write bad code though.

I won't profess that you should be doing everything in assembly, though. It has its places, but I wouldn't profess that it is the right idea for most code. In fact, some places where I've used it in my released code, it really shouldn't be used... But that is a different story all together. :lol:
Post Reply