Re: Probably a bug in LuaJIT x86

  • From: Mike Pall <mikelj-1808@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 16 Aug 2018 23:02:23 +0200

Egor Skriptunoff wrote:

On Thu, Aug 16, 2018 at 10:54 AM, Mike Pall wrote:
Compilation warning is displayed when building latest LuaJIT 2.1 under
VS2010:
   lib_base.c(302) : warning C4146: unary minus operator applied to
unsigned type, result still unsigned

The workaround to silence that warning with an intermediate cast
to a signed type may cause warnings from other tools about
potentially undefined behavior (negation of 0x80000000). Which
doesn't happen in practice, but the tools can't infer that.

Are the following two statements equivalent?
ul = -ul
ul = 1 + ~ul

There's a limit to which lengths one should go to shut up an
(unwarranted) compiler warning.

Negation is well defined for unsigned integers in C. It's just
'weird' to use it, so the compiler tries to be helpful. Whereas
with signed integers, the result is actually undefined for some
values (but in practice the result is the same).

I'd rather silence the warning, than use some tricky workaround
(which might in turn cause warnings with other compilers).

--Mike

Other related posts: