lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Le 25 Sep 2006 à 06:23, Glenn Maynard a écrit :

55I just had to point this out, for irony; VC7 gives:

   warning C4702: unreachable code

for this bit of code:

   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 happen to think there are entirely legitimate reasons for having unreachable code. For example you might have an ASSERT macro:

ASSERT(spong);

In fast reckless builds you might want to disable the macro, but it's nice if the condition argument to the macro still gets fed through the compiler so that the compiler can report any syntax violations or semantic checks. That means that a typo introduced into an ASSERT still gets caught when you do fast reckless builds. Define your macro something like this:

#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 like the unreachable code warning, but it often annoys too.

drj