Message-Id: <199910101551.JAA13611@lakdiva.slt.lk> From: "Kalum Somaratna" To: djgpp AT delorie DOT com Date: Sun, 10 Oct 1999 09:51:14 +0600 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: xmalloc and xfree In-reply-to: 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 Precedence: bulk On 9 Oct 99, at 15:21, Felix Natter 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 > #include > #include > #include > > 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 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 int main() { char *buffer = (char*)xmalloc(1000); xfree(buffer); return 0; } See you! Kalum