Thread: error: conflicting types

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    3

    error: conflicting types

    I'm trying to code a part of a compiler, and I'm getting that error message when I try to compile a test program.

    The program is at www.geocities.com/alienjedi1/mini-algol-60.zip

    The URL is a link to a zip file containing all the files (even though the problem is with just two of them). The complete error message is in the file called error.

    The error message is nothing specific to the project (it's not from any compiler building specific tools I'm using), just from GCC in unix.

    Could someone please tell me why I'm getting that error. The error is in y.tab.c and mini-algol-60.y Thanks so much.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    post the errors and the code on the lines where the error occurs.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    Error:
    Code:
    mini-algol-60.y:31: error: conflicting types for 'YYSTYPE'
    y.tab.h:6: error: previous declaration of 'YYSTYPE' was here
    mini-algol-60.y:122: error: conflicting types for 'yylval'
    y.tab.h:7: error: previous declaration of 'yylval' was here
    mini-algol-60.y:122: error: conflicting types for 'yylval'
    y.tab.h:7: error: previous declaration of 'yylval' was here
    make: *** [algol.o] Error 1
    y.tab.h
    Code:
    typedef union
    #ifdef __cplusplus
    	YYSTYPE
    #endif
     { int i; tree p; } YYSTYPE;
    extern YYSTYPE yylval;
    mini-algol-60.y line 122
    Code:
    { $$ = buildIntTree( IntConst, $1 ); }
    $$ is of type tree.

    Relevant structures used.
    Code:
    typedef struct tree_node
    {
    	int	kind, value;
    	struct tree_node *first, *second, *third, *next;
    } node;
    
    typedef node* tree;
    
    tree buildIntTree (int kind, int val)
    {
    	tree p = (tree)malloc(sizeof (node));
    	p->kind = kind;
    	p->value = val;
    	p->first = p->second = p->third = NULL;
    	p->next = NULL;
    	return p;
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well you need yacc/bison to compile a .y file, which will produce a .c file you can then compile with your C compiler.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    I did use yacc. I'm sorry for not being specific. I'm trying to compile algol.c. I wrote a make file that ran yacc (and lex for whatever that's worth), and then compile algol.c to produce a parser. It has no trouble making the y.tab.h and y.tab.c files. The problem lies with compiling algol.c. It's giving that wierd error several times.

    My question is what is the nature of that error message? What causes that kind of error? If I understood the problem better, then I could find a solution.

    Another interesting fact about the errors I listed - I'm not referencing the .y file anywhere. The errors are really coming from the y.tab.* files.

  6. #6
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    This error message occurs when you don not make a function prototype decleration. Try to add something like <return_value> myfunction(type arg....) at the begining of your code.

    My IDE (Dev-C++) gave me the same error when I did not make a function prototye decelration at begining fo my code (but the function implemenration was after main()).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. invalid types 'int[int]' for array subscript
    By kolistivra in forum C++ Programming
    Replies: 6
    Last Post: 12-11-2010, 12:57 PM
  2. Generalising methods to handle multiple weapon types
    By Swarvy in forum Game Programming
    Replies: 2
    Last Post: 05-22-2009, 02:52 AM
  3. Replies: 6
    Last Post: 08-23-2008, 01:16 PM
  4. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM