cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/10/23:43:54

Message-Id: <199910111223.GAA28100@lakdiva.slt.lk>
From: "Kalum Somaratna" <kalum AT myflat DOT com>
To: djgpp AT delorie DOT com
Date: Mon, 11 Oct 1999 06:23:23 +0600
MIME-Version: 1.0
Subject: Re: xmalloc and xfree
In-reply-to: <wkbta7v2tg.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 10 Oct 99, at 14:05, Felix <f DOT natter AT ndh DOT net> Natter wrote:

> "Kalum Somaratna" <kalum AT myflat DOT com> writes:
> > 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.
> 
> did you also not get any warnings like "implicit declaration of ..." ?
> because that's what I got with gcc-2.8.1, and now with gcc-2.95.1
> it's getting an error message
> 
> > 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>
> 
> -------------------- gcc output ------------------------------------------
> Reading specs from c:/djgpp/lib/specs
> gcc version 2.95.1 19990816 (release)
>  c:/djgpp/lib/gcc-lib/djgpp/2.951/cpp.exe -lang-c++ -v -isystem 
c:/djgpp/bin/include -D__GNUC__=2 -D__GNUG__=2 -
D__GNUC_MINOR__=95 -D__cplusplus -Dunix -Di386 -DGO32 -
DMSDOS -DDJGPP=2 -DDJGPP_MINOR=2 -D__unix__ -
D__i386__ -D__GO32__ -D__MSDOS__ -D__DJGPP__=2 -
D__DJGPP_MINOR__=2 -D__unix -D__i386 -D__GO32 -
D__MSDOS -D__DJGPP=2 -D__DJGPP_MINOR=2 -
D__EXCEPTIONS test2.cpp C:\WINDOWS\TEMP\ccrggSGg.ii
> GNU CPP version 2.95.1 19990816 (release) (80386, BSD syntax)
> #include "..." search starts here:
> #include <...> search starts here:
>  c:/djgpp/lang/cxx
>  c:/djgpp/include
>  c:/djgpp/lang/cxx
>  c:/djgpp/lib/gcc-lib/djgpp/2.951/include
>  c:/djgpp/include
> End of search list.
> The following default directories have been omitted from the search path:
>  $DJDIR/lib/gcc-lib/djgpp/2.951/../../../../djgpp/include
> End of omitted list.
>  c:/djgpp/lib/gcc-lib/djgpp/2.951/cc1plus.exe C:\WINDOWS\TEMP\ccrggSGg.ii -m486 -malign-jumps=2 -malign-loops=2 -malign-functions=2 -m486 -malign-jumps=2 -malign-loops=2 -malign-functions=2 -quiet -dumpbase test2.cc -version -o C:\WINDOWS\TEMP\ccvoUZQi.s
> GNU C++ version 2.95.1 19990816 (release) (djgpp) compiled by GNU C version 2.95.1 19990816 (release).
> test2.cpp: In function `int main()':
> test2.cpp:4: implicit declaration of function `int xmalloc(...)'
> test2.cpp:5: implicit declaration of function `int xfree(...)'
> ---------------------------------------------------------------------------

Dear Felix,
Please forgive me for a little mistake on my part.
It appears that the definitions for xmalloc and xfree have been 
commented out in stdlib.h (reasons given by the designer's of 
DJGPP were "These vary in expected prototype, so we just don't 
prototype them." ).


I also use GCC 2.95.1 The reason I got no error messages or 
warnings is I used the C compiler wich is much more forgiving than 
the C++ compiler on undefined references. Also I didn't use the 
-Wall option wich would have given the warnings but since the C 
compiler doesn't categorise undefined references as error's the 
program linked sucessfully. 

The C++ compiler is quite a different beast altogether and is much 
stricter (no need even to specify -Wall for message) and 
immedietly aborts on an undefined reference due to it been based 
on the new ANSI C++ standard. 
The reason why gcc 2.81 worked is that I've noticed that gcc 2.81 
was much less stricter than gcc 2.95 when dealing with certain 
C++ coding aspects (for example I got away with const i =23;  in 
2.81 but in 2.95 I have to specify const int i=23;) and may have 
flagged an undefined reference as a warning instead of a error thus 
permitting compilation continue.

My solution was to uncomment out the relevant areas (xmalloc 
xfree and xrealloc) in stdlib.h and save the modified stdlib.h and 
then both the C and C++ versions compiled just fine.
Hope it works for you too.

Bye and take care!
Kalum <kalum AT myflat DOT com>
 

- Raw text -


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