delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/17/12:59:57

From: Hans-Bernhard Broeker <broeker AT acp3bf DOT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Implicit declaration
Date: 17 Feb 2000 08:24:11 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 28
Message-ID: <88gb7b$4vv$1@nets3.rz.RWTH-Aachen.DE>
References: <YBFq4.399$O2 DOT 11784 AT harpo>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 950775851 5119 137.226.32.75 (17 Feb 2000 08:24:11 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 17 Feb 2000 08:24:11 GMT
User-Agent: tin/1.4-19991113 ("No Labels") (UNIX) (Linux/2.0.0 (i586))
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Chewbaklava <kalit AT ctel DOT net> wrote:
> I have a rather simple program, it opens a fil, reads some stuff, allocates
> 2 arrays with malloc, and then prints them out and frees the arrays.  The
> problem is, I get 2 error messages that, of course may be nothing, but may
> be a problem waiting to happen.

You forgot to show us the actual warning messages, which is not a good
idea if you expect us to help you deciphering them. But I think it's
clear nevertheless: something about implicit declaration of function
malloc, in:

>  map = (int *) malloc((width * height * sizeof(int)));  <<-- Warning here

>  props = (int *) malloc((width * height * sizeof(int)));

The reason: you forgot to #include <stdlib.h>. That's the general rule
with 'implicit declaration' warnings that don't turn into 'unresolved
reference' errors at link time: you forgot to #include the header file
that declares the function the warning tells you about. If you also
get the unresolved reference error, you more likely just mistyped the
function's name.

And don't cast the return value of malloc(), in a C program. It serves
no useful purpose, but may hide bugs.

-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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