Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Implicit declaration

0 views
Skip to first unread message

Hans-Bernhard Broeker

unread,
Feb 17, 2000, 3:00:00 AM2/17/00
to
Chewbaklava <ka...@ctel.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 (bro...@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.

0 new messages