ffi.cast: weird behaviour

  • From: Wolfgang Pupp <wolfgang.pupp@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 26 Jun 2012 12:28:44 +0200

I've recently been surprised by weird (IMHO) behaviour of ffi.cast;
Consider this code:

local ffi = require'ffi'
local zeroneg = '\x00\x00\x00\x80'
local nan = '\xff\xff\xff\xff'

print(ffi.cast('float *', zeroneg)[0])
print(ffi.cast('float *', nan)[0])

I would have expected this to print -0 and nan. But it doesn't. I get
-0 and *nil* instead.
Is this intended?
Am I doing it wrong in the first place?

--Wolfgang

Other related posts: