This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: May I propose an extension and ask how difficult this would be?




> Now that I'm done ranting, do the people who think it's a failed idea have
> a better suggestion?  This seems to work with great elegance and utility
> in Java.

That's because in Java, exceptions cannot appear outside the Java code and
propogate in.  But in C++,

    extern "C"  void somefunc();
    void foo()  throw (stuff) {
        // buncha code
        somefunc();
        // bunch more code
    }

nothing prevents somefunc() from throwing an exception that isn't "stuff"
as somefunc() doesn't have to be written in C.  If I recall Stroustrup
correctly, this is one of the reasons that automatic-exception-specifications
were not added.  Other languages become involved.

(How common that actually is, I have no clue.  But I think that's the
reasoning.  Sanity check?)


As far as increased optomized possiblilties go, remember that exception
specifications carry a penalty of their own:  the extra code generated
(space) and executed (time) during that function call at runtime, to check
that the exception being thrown is on the approved list.  Any optomizations
you might get out of the specs would have to overcome those penalties before
"paying for themselves".

(And if you argue that the thrown exception is so rare that the extra
checking code isn't a penalty, then I have to ask:  if you expect exceptions
in that function /that/ rarely, why are you adding a specification?  :-)


> Java:
> 	+ Garbage Collection
> 	+ Exceptions are easy to implement
>
> C++:
> 	+ Parameterized types
> 	+ Fast compiled code

Nothing prevents you from adding "Garbage Collection" to the C++ list.  Just
because it isn't built-in to the language doesn't mean it's not possible or
already implemented.  But you knew that already, I'm just babbling now...


-- 
philip.edwards@{sn.wpafb,afrl}.af.mil
Targeting & Attack Radar              PGP ID              UFOs are real.
U.S. Air Force Research Labs        0xDBABC04F            The Air Force
Senior Unix Systems Administrator                         doesn't exist.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]