Homebrew Question Why does libnx disable exceptions by default?

rouhannb

New Member
OP
Newbie
Joined
Jul 2, 2020
Messages
2
Trophies
0
XP
57
Country
United States
The default Makefile for libnx projects has -fno-exceptions in CXXFLAGS. What is the reason for this? Are exceptions somehow unsupported with Atmosphère or libnx? I always thought exceptions were just a simple language construct, so I don’t see why they would cause any problems, but why else would they be disabled by default? Should I not be using them?
 
D

Deleted User

Guest
@duckbill007 But you can write your own c++ code and throw an exception.. There is no problem using C library in C++ code. So your statement don't work.

@rouhannb It is also a question in my mind why -fno-exceptions is in all template makefile. Maybe a way to discourage using exceptions and also all the example are in C hence -fno-exceptions. Otherwise I think there is no problem using them really. Please someone correct me if am wrong.

Edit: For example, libconfig has 2 type of header files, "H", and "H++". You can use both and both will work (not at the same time, write 2 programs). the "H" version manage error by returning error codes, and the H++ will manage error by throwing exception (as I remember). It is available in the pacman repository.

You can use the "H" version in your c++ code if you don't want to manage exception, otherwise use the "H++" version. In your C code you just can't use the "H++" version, because yes it is for C++.
 
Last edited by ,

duckbill007

Well-Known Member
Member
Joined
May 5, 2011
Messages
676
Trophies
1
XP
2,429
Country
Russia
@romain337, go and read what -fno-exceptions flag does.

Also, using C library in C++ code is allowed but using C++ exceptions in C code not allowed. And these are two totally different things.
 

catlover007

Developer
Developer
Joined
Oct 23, 2015
Messages
714
Trophies
1
XP
3,834
Country
Germany
there's a (partially reasonable) common sentiment against exceptions. For one some people see them as an lazy and improper way of error handling, because it's implicit. They're quite an unusal control flow element (jumping back by a lot, so the stack needs to be unwinded, destructors need to be called). Even though modern C++ compilers produce pretty good code where the path in which no exception is thrown is as fast as if they weren't even there, it's still another variable to keep track. And as a last reason, exceptions can sometimes complicate things, which can interfere with all kinds of other things.
 
Last edited by catlover007,

rouhannb

New Member
OP
Newbie
Joined
Jul 2, 2020
Messages
2
Trophies
0
XP
57
Country
United States
I’m pretty sure that libnx has some startup code in each app that calls main. Perhaps they didn’t want an uncaught exception to “fall out” of a homebrew program and screw something up in their code? Is that possible with C++?
 

catlover007

Developer
Developer
Joined
Oct 23, 2015
Messages
714
Trophies
1
XP
3,834
Country
Germany
I’m pretty sure that libnx has some startup code in each app that calls main. Perhaps they didn’t want an uncaught exception to “fall out” of a homebrew program and screw something up in their code? Is that possible with C++?
it likely has. Like I said, exceptions, similarly to rtti and virtual methods have some costs attached, which lead some people not to use them at all (especially on more restrained environments, which the switch isn't completely, but the makefile is probably based on the nintendo .

Usually if you have this kind of questions better ask directly on #switch-dev on EFnet IRC.
 

scandal_uk

Not Really There
Member
Joined
Oct 3, 2005
Messages
322
Trophies
0
Location
UK
XP
580
Country
United Kingdom
Exceptions are great but they are expensive. If we can clean-code our way to a leaner way of handling it then we do. That is what is being encouraged here - manage everything.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • Sicklyboy @ Sicklyboy:
    maaaaan that's so awesome but I also don't want to fork over a hundo for it
  • Veho @ Veho:
    The fuuuuu---
  • Veho @ Veho:
    I thought it was an actual xBox at that price.
  • Sicklyboy @ Sicklyboy:
    I wanna grab a 360 Slim and a 360 E one of these days. Missed the boat of getting them at their lowest though, once they were discontinued. Could've got them for cheap back when I was a broke 20 something working at Target, but then again, I was a broke 20 something working at Target
  • Veho @ Veho:
    Being broke is no fun.
  • K3Nv2 @ K3Nv2:
    @Sicklyboy, $150 isn't that bad for a jtag slim on ebay
  • Veho @ Veho:
    I only wish it was actually playable.
  • Veho @ Veho:
    There's a guy on the Tube of You that makes playable mechanical arcade games out of Lego. This could work on the same principle.
  • Veho @ Veho:
    Just a couple of guys taking their manatee out for some fresh air, why you have to molest them?
  • Veho @ Veho:
    Stupid Chinese shop switched their shipping company and this one is slooooooow.
  • LeoTCK @ LeoTCK:
    STOP BUYING CHINESE CRAP THEN
  • LeoTCK @ LeoTCK:
    SUPPORT LOCAL PRODUCTS, MAKE REVOLUTION
  • LeoTCK @ LeoTCK:
    THEY KEEP REMOVING LOCAL SHIt AND REPLACING WItH INFERIOR CHINESE CRAP
  • LeoTCK @ LeoTCK:
    THATS WHY MY PARTNER CANT GET A GOOTWEAR HIS SIZE ANYMORE
  • LeoTCK @ LeoTCK:
    HE HAS BIG FOOT AND BIG DUCK
  • LeoTCK @ LeoTCK:
    d*ck i mean*
  • LeoTCK @ LeoTCK:
    lol
  • Veho @ Veho:
    Mkay.
  • Veho @ Veho:
    I just ordered another package from China just to spite you.
  • SylverReZ @ SylverReZ:
    Leo could not withstand communism.
  • SylverReZ @ SylverReZ:
    Its OUR products to begin with lol.
    SylverReZ @ SylverReZ: Its OUR products to begin with lol.