exception from C function?



 DEVELOP > c-Plus-Plus > exception from C function?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "George2"
Date: 27 Jan 2008 09:13:11 PM
Object: exception from C function?
Hello everyone,
As far as I know, C function does not throw exception.
But Bjarne said in his book, section 14.8 Exception and Efficiency,
--------------------
In particular, an implementation knows that only a few standard C
library functions (such as atexit() and qsort()) can throw exceptions,
and it can take advantage of that fact to generate better code.
--------------------
What did he mean? C function could really throw exception? What
exception -- C++ exception or structured exception?
thanks in advance,
George
.

User: "Thomas J. Gritzan"

Title: Re: exception from C function? 27 Jan 2008 09:41:20 PM
George2 wrote:

As far as I know, C function does not throw exception.

But Bjarne said in his book, section 14.8 Exception and Efficiency,

--------------------
In particular, an implementation knows that only a few standard C
library functions (such as atexit() and qsort()) can throw exceptions,
and it can take advantage of that fact to generate better code.
--------------------

What did he mean? C function could really throw exception? What
exception -- C++ exception or structured exception?

There are no structured exceptions in C++ world (it's a MS Windows specific
thing), so Bjarne meant C++ exceptions.
atexit() and qsort() both take function pointers to callback function that
get called at some time and these functions could throw an exception. So
atexit() and qsort() can indirectly throw exceptions.
--
Thomas
http://www.netmeister.org/news/learn2quote.html
post tenebras lux. post fenestras tux.
.
User: "James Kanze"

Title: Re: exception from C function? 28 Jan 2008 03:46:49 AM
On Jan 28, 4:41 am, "Thomas J. Gritzan" <Phygon_ANTIS...@gmx.de>
wrote:

George2 wrote:

As far as I know, C function does not throw exception.
But Bjarne said in his book, section 14.8 Exception and Efficiency,
--------------------
In particular, an implementation knows that only a few standard C
library functions (such as atexit() and qsort()) can throw exceptions,
and it can take advantage of that fact to generate better code.
--------------------
What did he mean? C function could really throw exception? What
exception -- C++ exception or structured exception?

There are no structured exceptions in C++ world (it's a MS
Windows specific thing), so Bjarne meant C++ exceptions.
atexit() and qsort() both take function pointers to callback
function that get called at some time and these functions
could throw an exception. So atexit() and qsort() can
indirectly throw exceptions.

I wouldn't be so sure about atexit(). It's pretty much
guaranteed that the function you pass to it won't be called
until after atexit() returns. (Threading issues aside, but if
you're calling exit() in one thread, and atexit() in another,
you've got real problems in your code.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.


User: "James Kanze"

Title: Re: exception from C function? 28 Jan 2008 03:44:29 AM
George2 wrote:

As far as I know, C function does not throw exception.
But Bjarne said in his book, section 14.8 Exception and Efficiency,
--------------------
In particular, an implementation knows that only a few standard C
library functions (such as atexit() and qsort()) can throw exceptions,
and it can take advantage of that fact to generate better code.
--------------------
What did he mean? C function could really throw exception? What
exception -- C++ exception or structured exception?

qsort() (and bsearch()) call a function through a pointer,
passed in as an argument. The function they call might throw an
exception, which will then (normally) propagate through the
library function out to user code. (Although atexit() also
takes a pointer to a function, I rather doubt that it can raise
an exception, since it doesn't call that function during its
execution.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER