'myvar' undeclared (first use this function)
This tells you that the variable myvar hasn't been
declared. This means that you forgot to provide a declaration (such as
int myvar
) to this scope. The variable needs to be declared
either within the same set of braces {}, or in an enclosing scope:
{ int myvar;
{
/* myvar is still known here */
}
}
or at the top level (outside ANY set of braces) so that it is globally known.
In function `main':
warning: implicit declaration of function `f'
This tells you that the declaration for the function f
doesn't occur until after it is called in function main
.
main
will be compiled with the assumption that f
returns an int (C is defined that way). If f
returns something
else, you will see another message later (see the next
common error). This warning is resolved by either moving the function
f
so that it occurs before main
in the source
file, or better yet, by copying f
's prototype to a place before
main
:
float f (void); /* Notice the semicolon: this is a prototype */
/* i.e. This is a declaration, not a */
/* for the function f(). */
void main (void)
{
float a;
...
a = f();
...
}
float f (void) /* NO semicolon: this is the function def'n */
{
...
}
ttt.c: At top level:
ttt.c:9: warning: type mismatch with previous external decl
ttt.c:5: warning: previous external decl of `f'
ttt.c:9: warning: type mismatch with previous implicit declaration
ttt.c:5: warning: previous implicit declaration of `f'
ttt.c:9: warning: `f' was previously implicitly declared to return `int'
This tells you that when f()
is defined starting about line
9, the type it is declared with differs from that implied by calling it on
line 5. Because there was no prototype or definition for f()
before it was called on line 5 in main()
, it was assumed to
return an int as per the C language definition. This is called an
implicit declaration. When the definition for
f()
declared it to return a float, it mismatched with the
assumed declaration. The solution is to prototype f()
before
it is called in main()
or to move the definition of
f()
before main()
in the source. See the
example in the previous common error.
This can be many things, including (but not limited to):
This means that a comment was opened with (/*) but not closed by the end of the file. You are missing the corresponding (*/).