www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/10/09/15:25:38

From: Mihai Moise <moisemih AT ift DOT ulaval DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: compiler troubles
Date: Wed, 09 Oct 1996 12:30:22 -0400
Organization: Universite Laval
Lines: 79
Message-ID: <325BD31E.41C67EA6@ift.ulaval.ca>
References: <3 DOT 0b26 DOT 32 DOT 19961004162450 DOT 00685b9c AT cis DOT cisnet DOT com>
NNTP-Posting-Host: britten.ift.ulaval.ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019