Re: ffi : creating char **

  • From: Nagaev Boris <bnagaev@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 6 Jun 2016 19:03:00 +0300

On Mon, Jun 6, 2016 at 6:52 PM, Iwan Budi Kusnanto <ibk@xxxxxxxxxxxx> wrote:

Hi All,

How is the correct way to create `char **` with ffi?

I have done these ways:
-- create char[][]
local data = ffi.new("char["..k.."]["..m.."]")

-- cast it when calling C function
ffi.cast("char **", data)

But it doesn't work for me, i got segmentation fault error.


--
Iwan Budi Kusnanto


Hi,

char** and char[k][m] are different data structures.

char** is a pointer to pointer to char

char[k][m] is 2-dimensional array of char, which is stored as char[m]
repeated k times and can be casted to char* not to char**

-- 


Best regards,
Boris Nagaev

Other related posts: