[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: loslib.c warning
- From: Glenn Maynard <glenn@...>
- Date: Mon, 25 Sep 2006 06:52:27 -0400
On Mon, Sep 25, 2006 at 10:59:57AM +0100, David Jones wrote:
> > exit(luaL_optint(L, 1, EXIT_SUCCESS));
> > return 0; /* to avoid warnings */
> >
> >I'd recommend removing this; it's introducing a legitimate warning in
> >order to fix a buggy one.
>
> It entirely depends on what compiler one is using and what warnings
> you have enabled.
I disagree. The warning that this is (presumably) meant to fix is "no
return value in function returning non-void". Any compiler implementing
that warning should also be implementing __attribute__((noreturn)) or
equivalent.
glibc does it: extern void exit (int __status) __THROW __attribute__ ((__noreturn__));
and VC does it (since VC6): _CRTIMP __declspec(noreturn) void __cdecl exit(int);
The "unreachable code" warning may have pros and cons, but handling
"noreturn" to avoid spurious return value warnings is basic. That's
why it seems like a backwards trade. (Even if it's a minor one; the
only reason I bothered mentioning it was because I found it funny that
a line with the comment "to avoid warnings" was the cause of a warning.)
I wonder what compiler this was actually for. CodeWarrior?
> #define ASSERT(x) if(1) {} else do { sizeof(x); } while(0)
>
> This way the compiler still checks the condition for syntax, etc, but
> no code gets generated. There's lots of unreachable and dead code.
I havn't seen a compiler that would trigger that warning on this code;
that would be a bit over-sensitive.
--
Glenn Maynard