Thread: C struct and a bit of yacc

  1. #1
    Registered User
    Join Date
    Jan 2008

    C struct and a bit of yacc

    I have the following code in yacc:

    typedef struct data {
         int type;
         union {
            float f;
            char *str;
            int v;
         } d;
    } data;
       data *typ;  ==> error occurs here in the
       char* stringcon;
       char charcon;
       char *id;
    %type <typ> expr
    however it gives me an error : error: expected specifier-qualifier-list before ‚data‚

    Can someone tell me why?

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    How about listening to and heeding to the words of your compiler. I see an error on line 22 that causes line 24 to become confused. Please just copy and paste code directly next time.

  3. #3
    Registered User
    Join Date
    Nov 2009
    you have the same name for the typedef and the struct, thats name must be different.
      typedef struct strdata {...} data;

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Quote Originally Posted by evaristoyoka
    you have the same name for the typedef and the struct, thats name must be different.
    No, that is fine. The typedef defines data as an alias for struct data.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed
Website Security Test