Possibly confusing documentation on FFI page w.r.t enum redeclaration?

  • From: demetri <demetri.spanos@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 15 Nov 2013 13:19:08 -0800

Hello LuaJIT,

I was wondering whether it might be useful to qualify the statement at
http://luajit.org/ext_ffi_semantics.html#status regarding ffi.cdef silently
ignoring re-declarations, specifically with respect to declarations of
enums
that include an identifier list.

In a nutshell, all the following redeclaration variants work as expected,
i.e.
they silently do nothing:

local decls = {
  [[ void printf(const char*, ...) ]],
  [[ struct {int a,b;} mystruct; ]],
  [[ enum things; ]]
}
for i=1,#decls do
  ffi.cdef(decls[i])
  ffi.cdef(decls[i]) -- re-run the declarations, nothing happens
end

But this variant isn't silently ignored (enum declared with an identifier
list):

local decls = {[[ enum {foo=1, bar=2} things; ]]}

My understanding of why this chokes when run twice is that the declaration
of "things" also contains a definition (not declaration) of foo and bar.
Still, I
believe that one could, based on the documentation, reasonably expect the
entire declaration to be ignored the second time around even though it
included definitions inside. Unless I'm misunderstanding C's grammar (I may
well be!) the entire text of "enum {identifier list} name" is a declaration.

I apologize for what may seem like nit-picking, but several of our team's
newcomers to LuaJIT have bumped into this so I thought it might be a source
of wider confusion. FWIW I've found no mention of this anywhere when
searching the FFI doc pages, the wiki, and the mailing list archives.

Cheers,
Demetri

Other related posts: