[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Trouble running Lua script from C++ application
- From: David Given <dg@...>
- Date: Sat, 28 Jun 2008 12:24:44 +0100
James Dennett wrote:
[...]
> int f() {
> g();
> }
>
> in the case where g() never returns normally (i.e., it terminates
> execution or throws an exception). Warning about f would be bad in
> those cases, but failing to warn if g() ever does return is bad too,
> and adding runtime checks is also bad (as it adds overhead).
This is why most compilers have a way of declaring functions as 'does
not return'.
extern void g(void);
int f() { g(); }
=> test.c:2: warning: control reaches end of non-void function
#define NORETURN __attribute__ ((__noreturn__))
extern void g(void) NORETURN;
int f() { g(); }
=> compiles cleanly. (This is with gcc. Other compilers will need
different syntax, alas.)
Also, using NORETURN will generate better code. In the above example,
when using NORETURN the compiler omits the function epilogue from f()
because it knows it's not necessary.
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup
Attachment:
signature.asc
Description: OpenPGP digital signature