Mail Archives: djgpp/1996/10/09/15:25:38
Dr Eclipz wrote:
>
> djgpp gives me variations of the following warnings:
>
> Warning: previous implicit declaration of '[function name]'
> Warning: '[function name]' was previously implicitly declared to return 'int'
> Warning: type mismatch with previous implicit declaration
You should NEVER implicitly declare a function. Sometimes the code will
be good, but other times it will play havoc. Here is what I am talking
about:
int main ( void ) {
my_function();
}
void my_function ( void ) {
...
}
Will cause the first two warnings. When a function is used before it is
declared, GCC expects it to return an int by default.
Three approaches will solve the problem, but only the last two are good.
1:
int my_function ( void ) {
...
}
2:
void my_function ( void );
int main ( void ) {
my_function();
}
3:
void my_function ( void ) {
...
}
int main( void ) {
my_function();
}
Yesterday, I tried to compile a plug-in for GIMP which did implicit type
conversion ( finally got it to compile ), so for now I believe that all
those who do it should be hanged. This is what I am talking about:
u_char* function() {
...
}
main ( void ) {
int a = function();
}
You have been warned.
> Warning: type mismatch with previous external decl
>
>
something like:
extern int my_var;
char my_var;
should generate this warning.
Good luck!
Mihai
- Raw text -