Re: newbie question: ffi.sizeof()

  • From: Patrick Masotta <masottaus@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 20 Jun 2012 03:27:25 -0700 (PDT)

you are right, the problem is the function (not LUA) that I'm using to print 
the numeric value
Thanks guys.


--- On Wed, 6/20/12, Peter Cawley <corsix@xxxxxxxxxx> wrote:


From: Peter Cawley <corsix@xxxxxxxxxx>
Subject: Re: newbie question: ffi.sizeof()
To: luajit@xxxxxxxxxxxxx
Date: Wednesday, June 20, 2012, 3:12 AM



On Wed, Jun 20, 2012 at 11:07 AM, Patrick Masotta <masottaus@xxxxxxxxx> wrote:







I did what you say but I'm getting sz=0, not 50 as expected ... :-(
The C string is there with the correct initial value and all of that..
I just cannot get its size.
what could be wrong?
It seems to give the correct result for me:

E:\CPP\2010\LuaJIT-2.0.0-beta10\bin>luajit.exe
LuaJIT 2.0.0-beta10 -- Copyright (C) 2005-2012 Mike Pall. http://luajit.org/
JIT: ON CMOV SSE2 SSE3 SSE4.1 fold cse dce fwd dse narrow loop abc fuse
> ffi = require"ffi"
> var_01 = ffi.new("char[50]", "initial value for var_01" )
> sz = ffi.sizeof(var_01)
> print(sz)
50

If you're not seeing the correct result, then reduce your code to a minimal 
test case like above, and we'll probably be able to identify the problem.

Other related posts: