Note that there are some explanatory texts on larger screens.

plurals
  1. POerror: conflicting types for 'x'
    text
    copied!<p>I am new to C, and I've read a number of posts trying to deal with this issue, and they all say that the error message:</p> <pre><code>error: conflicting types for 'x' </code></pre> <p>occurs because a function is used before it is declared. This is not (at least not in an obvious way) the case with my code.</p> <p>I have several files in my project:</p> <ul> <li><code>minty.c</code></li> <li><code>lexer.c</code></li> <li><code>lexer.h</code></li> <li><code>minty_util.c</code></li> <li><code>minty_util.h</code></li> </ul> <p>I compile <code>lexer.c</code> and <code>minty_util.c</code> with:</p> <pre><code>gcc -Wall -g -c lexer.c -o lexer.o gcc -Wall -g -c minty_util.c -o minty_util.o </code></pre> <p>and these both compile successfully. The error comes when I try to compile <code>minty.c</code>:</p> <pre><code>gcc -Wall -g minty.c lexer.o minty_util.o -o minty </code></pre> <p>At which point I get about 6 errors of the form given above (where <code>x</code> is a function name) for functions declared in <code>minty_util.h</code> and defined in <code>minty_util.c</code>. From what I have read, it may have something to do with the way each file <code>#includes</code> other files, so here are the includes for each file (the obvious stuff like <code>stdio.h</code> is omitted):</p> <ul> <li><code>minty.c</code> includes <code>minty_util.h</code> and <code>lexer.h</code></li> <li><code>lexer.c</code> includes <code>lexer.h</code></li> <li><code>lexer.h</code> includes <code>minty_util.h</code> (because it contains forward declarations using typedefs specified in <code>minty_util.h</code>)</li> <li><code>minty_util.c</code> includes <code>minty_util.h</code></li> <li><code>minty_util.h</code> does not include anything</li> </ul> <p>If anyone can shed any light on why I'm having this problem, it would be immensely appreciated, as I have been trying to figure this out for hours (should've posted earlier!).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload