Re: array of complex

  • From: demetri <demetri.spanos@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 17 Jul 2015 00:52:34 -0700


So I try to use ffi.cast('complex*', p) and get the message

cannot convert 'complex *' to 'complex *'


Could you clarify a bit, perhaps with a specific reproduction
script? I tried to reproduce your problem naively with the
following:

-- begin complextest.lua
local ffi = require "ffi"
ffi.cdef [[
void printf(const char*, ...)
]]

local a = ffi.new("complex[?]",2,{1,2},{3,4})
print(a,a[0],a[1])
ffi.C.printf("%f %f %f %f\n",a[0],a[1],a[2],a[3])

local b = ffi.cast("complex*",a)
print(b,b[0],b[1])
ffi.C.printf("%f %f %f %f\n",b[0],b[1],b[2],b[3])
-- end complextest.lua

This prints on my machine (OSX, tested with the most
recent 2.0.1 and also a 2.1 from about a month ago):

~ $ luajit complextest.lua
cdata<complex [?]>: 0x0004bcf8 1+2i 3+4i
1.000000 2.000000 3.000000 4.000000
cdata<complex *>: 0x0004bcf8 1+2i 3+4i
1.000000 2.000000 3.000000 4.000000

So superficially it seems like I can get complex[?]
in a cast to complex* and that both work fine as
arguments to C functions. Of course this isn't testing
a C function expecting a complex* but I didn't have
one handy. But if that's the source of the trouble then
perhaps this is a step toward isolating it.

Demetri

Other related posts: