Re: FFI in interpreter mode

  • From: Tony Finch <dot@xxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 24 May 2012 12:17:19 +0100

James McKaskill <james@xxxxxxxxxxxx> wrote:
>
> >  * Similarly, something was typedef'd as an unsigned int and turned into an 
> > enum later:
> >  *   type 'enum ' previously declared as 'unsigned int'
>
> Wow. You learn something new every day. I didn't even know this was
> legal C. Filed as https://github.com/jmckaskill/luaffi/issues/30

It is not. You cannot declare a typedef name more than once, whether or
not the types match. (Where C allows redeclarations - of external objects
and structure tags - the duplicates have to be the same thing.)
With reference to C99 incorporating all three technical corrigenda:
http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf

Section 6.2.2p6:

  The following identifiers have no linkage: an identifier declared to be
  anything other than an object or a function; an identifier declared to
  be a function parameter; a block scope identifier for an object declared
  without the storage-class specifier extern.

Section 6.7p3

  If an identifier has no linkage, there shall be no more than one
  declaration of the identifier (in a declarator or type specifier) with
  the same scope and in the same name space, except for tags as specified
  in 6.7.2.3.

$ cat typedef.c
typedef int thingy;
typedef int thingy;
$ gcc -c typedef.c
typedef.c:2: error: redefinition of typedef 'thingy'
typedef.c:1: error: previous declaration of 'thingy' was here

Tony.
-- 
f.anthony.n.finch  <dot@xxxxxxxx>  http://dotat.at/
Dogger: Southeast 3 or 4. Slight or moderate. Fog patches at first in west.
Moderate or good, occasionally very poor at first in west.

Other related posts: