Re: ffi.sizeof and variable length structs (VLS)

  • From: Aleksandar Kordic <alexandarkordic@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 24 May 2018 18:06:30 +0200

On Thu, May 24, 2018 at 3:12 PM, Konstantin Stefanov <cstef@xxxxxxxxxxx>
wrote:

Why not accept int a[] as if it were 'int a[?]'


Those 2 declarations are not equivalent.

You can prepare declaration in text if that is more intuitive to you:

local ffi = require("ffi")

local exact_c_definition = string.format([[
struct vls_s {
        int n;
        int a[%d];
}
]], 2)

ffi.cdef(exact_c_definition)

local vls = ffi.new("struct vls_s")

local s1 = ffi.sizeof(vls)
local s2 = ffi.sizeof("struct vls_s")

print(s1)
print(s2)

It prints
12
12

Other related posts: