[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [LuaJIT ffi] Misleading error message?
- From: Mike Pall <mikelu-1107@...>
- Date: Sat, 23 Jul 2011 16:44:37 +0200
Thomas Lauer wrote:
> The following code, run under Windows, produces an error message for
> line 4 which IMHO is misleading at best but more probably spurious?
> ffi.cdef('void DebugBreak(void);') -- Any function will do
> if ffi.C.DebugBreak then print(ffi.C.DebugBreak) end -- OK
> if ffi.C.DebugBreak~=nil then print(ffi.C.DebugBreak) end
> luajit.exe: f:\testffi.lua:4: attempt to compare 'void ()' with 'void *'
Well, the error message is correct. You're comparing a function
with nil (which is treated like a pointer to void here).
But it's debatable whether comparing a function with a pointer
should be disallowed. In C, functions and function pointers are
almost universally exchangeable, so I guess this should be
allowed here. I've changed the semantics in git HEAD.
[But note that neither of two conditionals in your code can ever
be true. Only nil and false are treated as not-true conditions.
And GetProcAddress() returns NULL on error, so there cannot be a
dynamically resolved function with a NULL address.]