1. rouhannb

    OP rouhannb Newbie
    Newcomer

    Joined:
    Jul 2, 2020
    Messages:
    2
    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?
     
  2. duckbill007

    duckbill007 GBAtemp Regular
    Member

    Joined:
    May 5, 2011
    Messages:
    157
    Country:
    Russia
    Because libnx written in C, not in C++.

    And C has no exceptions.
     
  3. romain337

    romain337 GBAtemp Regular
    Member

    Joined:
    Jan 7, 2016
    Messages:
    143
    Country:
    France
    @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 romain337, Jul 3, 2020
  4. duckbill007

    duckbill007 GBAtemp Regular
    Member

    Joined:
    May 5, 2011
    Messages:
    157
    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.
     
  5. catlover007

    catlover007 Developer
    Developer

    Joined:
    Oct 23, 2015
    Messages:
    504
    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, Jul 3, 2020
  6. romain337

    romain337 GBAtemp Regular
    Member

    Joined:
    Jan 7, 2016
    Messages:
    143
    Country:
    France
    I think we say the same thing but we are lost in translation :P
     
  7. rouhannb

    OP rouhannb Newbie
    Newcomer

    Joined:
    Jul 2, 2020
    Messages:
    2
    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++?
     
  8. catlover007

    catlover007 Developer
    Developer

    Joined:
    Oct 23, 2015
    Messages:
    504
    Country:
    Germany
    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.
     
  9. scandal_uk

    scandal_uk Not Really There
    Member

    Joined:
    Oct 3, 2005
    Messages:
    306
    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.
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - exceptions, disable, default