error: field has incomplete type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nina01
    New Member
    • Jan 2009
    • 8

    error: field has incomplete type

    Hi everybody!!
    I'm actually trying to construct a compiler with flex and bison. But when I try to compile the"lex.yy.c" file on cygwin I keep having this error:

    Code:
    $gcc -c lex.yy.c
    In file included from Simple.l:4
    Simple.y:60: error: field 'typeval' has incomplete type
    In fact, typeval's type is an enum 'type' that I've defined in 'ST.h':
    Code:
    typedef enum type type;
    enum type {Int, Bool} ;
    and tht I'v included in 'Simple.y':
    Code:
    #ifndef ST_H
    #define ST_H
    #include "ST.h"
    #endif
    ......
    %union semrec { int    intval; 
         char    *id; 
        enum type typeval; //line: 60
        struct lbs *lbls; }
    I really don't know what to do in order to fix this error :-(
    Help pleeease! It's urgent...
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    This compiles on my mingw (gcc3.4.5 )
    \MinGW\bin\gcc. exe b.c

    Code:
    typedef enum type type;
    enum type {Int, Bool};
    union semrec { int    intval; 
         enum type typeval; //line: 60
     };

    Comment

    • nina01
      New Member
      • Jan 2009
      • 8

      #3
      First of all, thanks for your reply...
      I don't think this is due to cygwin because the program compiled without any problem before I added that enum. :-(

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Originally posted by nina01
        Code:
        typedef enum type type;
        enum type {Int, Bool} ;
        Code:
        %union semrec { int    intval; 
             char    *id; 
            enum type typeval; //line: 60
            struct lbs *lbls; }
        1. In the typedef you ask the compiler to consider typedef name 'type' to mean the same as 'enum type'. At this point you haven't told the compiler what 'enum type' is. Although I think this kind of forward reference is legitimate, it might be stressing your compiler. I suggest moving the typedef after the enum. By the way, you could combine these two statements:
        Code:
        typedef enum type {Int, Bool} type;
        2. You are using the same name for the enum and the typedef. These are different namespaces, so the compiler won't get confused; but you might. Consider making them different. Are you even sure you need to reference both the enum and the typedef? Perhaps you could use the combined form with an anonymous enum.

        3. The typeval field is defined as 'enum type'. You aren't even using the typedef name here. Either remove the word 'enum' or reconsider whether you even need the typedef.

        Comment

        • nina01
          New Member
          • Jan 2009
          • 8

          #5
          Thanks donbock for your reply.
          I've tried removing the "typedef" but the error remains the same.
          When I let the "typedef" and remove the "enum" (in "typeval" definition) I start getting too many errors.
          I don't know what I'm doing wrong...

          Comment

          • newb16
            Contributor
            • Jul 2008
            • 687

            #6
            Simple.y:60:
            %union semrec { int intval;
            Just in case - is there really %union ( with percent sign) that compiler try to parse? And has ST.h actually got included there?

            Comment

            • nina01
              New Member
              • Jan 2009
              • 8

              #7
              yes. This is the way we declare a union at bison. In fact, I got it from an exemple I found in a book about flex and bison.

              Comment

              Working...