www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/10/03:50:44

Message-Id: <199910101551.JAA13611@lakdiva.slt.lk>
From: "Kalum Somaratna" <kalum AT myflat DOT com>
To: djgpp AT delorie DOT com
Date: Sun, 10 Oct 1999 09:51:14 +0600
MIME-Version: 1.0
Subject: Re: xmalloc and xfree
In-reply-to: <wkwvsw656d.fsf@mail.ndh.net>
X-mailer: Pegasus Mail for Win32 (v3.12)
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On 9 Oct 99, at 15:21, Felix Natter <f DOT natter AT ndh DOT net> wrote:

> hi,
> I am using xmalloc and xfree
> to allocate memory, but gcc2.95(.1) (2.02, bnu 2.81) gives
> me error messages because it can't find
> xmalloc and xfree (undefined references).
> with gcc-2.81 (2.01, bnu2.81) I always
> got warnings like implicit declaration of xmalloc/xfree,
> but I ignored these since I thought that
> these two functions are included in the startup-code
> and thus wouldn't have a header file.
> 
> here's an example:
> the header files I've included and
> the prototypes
> are just attempts to find one where xfree
> and xmalloc are defined in, because
> I thought that the problem might be that
> the compiler can't find a definition,
> and thus uses the "implicit declarations"
> which in turn won't be recognized by
> the compiler at link-time ??
> 
> ------------------------
> #include <stdlib.h>
> #include <sys/djtypes.h>
> #include <sys/types.h>
> #include <stddef.h>
> 
> int xmalloc(size_t size);
> void xfree(void* buffer);
> 
> int main() {
>   char *buffer = (char*)xmalloc(1000);
>   xfree(buffer);
>   return 0;
> }
> -----------------------
> 
> are xmalloc and xfree deprecated or
> is there a better or more portable (i.e. Linux)
> way to do allocation-checking ?
> 
> thanks,
> ---
> Felix Natter
> 

Hi Felix,
The header file wich contain's the definition is stdlib.h  as 
documented in the doc's.

 #include <stdlib.h>
 void *xmalloc(size_t size);

It is strange that you got the messages. I compiled your program 
and it linked without any problems and I also didn't get any 
undefined reference's.
Could you please try compiling the following code and add the -v 
switch (ie- gcc test.c -o test.exe -v ) and post the output of gcc 
please so we can see what exactly is happening. You can use 
something like( gcc test.c -o test.exe -v >output.txt ) and post 
what was in output.txt.

#include <stdlib.h>
 int main() {
   char *buffer = (char*)xmalloc(1000);
   xfree(buffer);
   return 0;
 }

See you!
Kalum <kalum AT myflat DOT com>

- Raw text -


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