* malloc() in /usr/include files
@ 1995-04-19 4:00 Jon Howell
1995-04-19 4:00 ` Dan Pop
1995-04-19 4:00 ` Daniel S. Riley
0 siblings, 2 replies; 3+ messages in thread
From: Jon Howell @ 1995-04-19 4:00 UTC (permalink / raw)
Okay, I'm a little perplexed. First, background:
OSF 3.0, gcc/g++ 2.6.3, libg++ 2.6.2.
Now I'm trying to build some C++ code with g++. I have two files which
require malloc and friends; when I #include </usr/include/malloc.h> in them,
I get:
195 jonh@stout/alpha> make
g++ -pedantic -c chunk.cxx
chunk.cxx: In method `GSchunk::~GSchunk()':
chunk.cxx:21: warning: implicit declaration of function `int free(...)'
chunk.cxx: In method `enum GSErr GSchunk::installChunk(class GSgroupManager *)':
chunk.cxx:35: warning: implicit declaration of function `int malloc(...)'
chunk.cxx:35: warning: assignment to `void *' from `int' lacks a cast
g++ -pedantic -c list.cxx
list.cxx: In method `GSlist::~GSlist()':
list.cxx:18: warning: implicit declaration of function `int free(...)'
list.cxx: In method `int GSlist::insertItem(class GSlistMember *)':
list.cxx:28: warning: implicit declaration of function `int realloc(...)'
list.cxx:31: warning: implicit declaration of function `int calloc(...)'
g++ -pedantic -o try try.o chunkManager.o groupManager.o chunk.o chunkRef.o list.o listMember.o ipcAgent.o chunkIDHash.o gsErr.o GROUPchunk.o
And it compiles, but with heinous errors. Why aren't malloc() and friends
prototyped in the standard include files?
Furthermore, when I write my own prototypes and recompile with my own local
"malloc.h":
#include <stdio.h>
void *malloc(size_t size);
void *calloc(size_t num_of_elts, size_t elt_size);
void *realloc(void *pointer, size_t size);
void free(void *pointer);
I get:
g++ -pedantic -c chunk.cxx
g++ -pedantic -c list.cxx
g++ -pedantic -o try try.o chunkManager.o groupManager.o chunk.o chunkRef.o list.o listMember.o ipcAgent.o chunkIDHash.o gsErr.o GROUPchunk.o
/bin/ld:
Unresolved:
free__FPv
malloc__FUl
realloc__FPvUl
calloc__FUlUl
collect2: ld returned 1 exit status
*** Exit 1
Stop.
It appears my prototypes got whunked into the C++ naming conventions, so that
they wouldn't link with the symbols named in the standard libraries.
My questions:
1. Why doesn't OSF/1 prototype malloc() and friends? I did a find -exec
grep, and nothing under /usr/include appeared to prototype malloc().
2. How do I find out more about C++ symbol-munging? I'd like to know
the hows and whys, and how I can say in a prototype that this is a
boring old C function, so don't munge the symbol name.
Thanks many,
--Jon
Jon Howell 206-616-1478 voice
Systems Administrator 206-543-5380 fax
Human Interface Technology Lab. jonh@hitl.washington.edu
University of Washington, FJ-15
Seattle, Washington 98195
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: malloc() in /usr/include files
1995-04-19 4:00 malloc() in /usr/include files Jon Howell
@ 1995-04-19 4:00 ` Dan Pop
1995-04-19 4:00 ` Daniel S. Riley
1 sibling, 0 replies; 3+ messages in thread
From: Dan Pop @ 1995-04-19 4:00 UTC (permalink / raw)
In <Pine.OSF.3.91.950419104826.8485M-100000@stout.hitl.washington.edu> Jon Howell <jonh@hitl.washington.edu> writes:
>Okay, I'm a little perplexed. First, background:
>
> OSF 3.0, gcc/g++ 2.6.3, libg++ 2.6.2.
>
>Now I'm trying to build some C++ code with g++. I have two files which
>require malloc and friends; when I #include </usr/include/malloc.h> in them,
Wrong header. Use #include <stdlib.h> instead, as required by ANSI C.
>My questions:
> 1. Why doesn't OSF/1 prototype malloc() and friends? I did a find -exec
> grep, and nothing under /usr/include appeared to prototype malloc().
Try "grep malloc /usr/include/stdlib.h". It works on my OSF/1 2.1 box.
> 2. How do I find out more about C++ symbol-munging? I'd like to know
> the hows and whys, and how I can say in a prototype that this is a
> boring old C function, so don't munge the symbol name.
>
The common practice is something like this:
extern "C"
{
/* put here all the prototypes for the "boring old C functions" */
}
Dan
--
Dan Pop
CERN, CN Division
Email: danpop@afsmail.cern.ch
Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: malloc() in /usr/include files
1995-04-19 4:00 malloc() in /usr/include files Jon Howell
1995-04-19 4:00 ` Dan Pop
@ 1995-04-19 4:00 ` Daniel S. Riley
1 sibling, 0 replies; 3+ messages in thread
From: Daniel S. Riley @ 1995-04-19 4:00 UTC (permalink / raw)
In article <Pine.OSF.3.91.950419104826.8485M-100000@stout.hitl.washington.edu>,
Jon Howell <jonh@hitl.washington.edu> writes:
jonh> 1. Why doesn't OSF/1 prototype malloc() and friends?
It does:
dsr_lns101% egrep 'malloc|free|calloc' /usr/include/stdlib.h
extern void *calloc __((size_t , size_t ));
extern void free __((void *));
extern void *malloc __((size_t ));
right where they are supposed to be, according to ANSI section 7.10.3.
jonh> 2. How do I find out more about C++ symbol-munging? I'd like
jonh> to know the hows and whys, and how I can say in a prototype
jonh> that this is a boring old C function, so don't munge the
jonh> symbol name.
The how and why is that because of overloading, and the desire for
type-safe linkage, the mangled name of the function has to include
information about the argument types. To tell the compiler that it is
a C function, declare 'em as
extern "C" {
void *malloc(size_t size);
void *calloc(size_t num_of_elts, size_t elt_size);
void *realloc(void *pointer, size_t size);
void free(void *pointer);
}
This gets done for you in /usr/include/stdlib.h, but is obscured
somewhat by the use of the _BEGIN_CPLUSPLUS/_END_CPLUSPLUS macros to
do it. If you *really* want all the hows and whys, read the Annotated
Reference Manual.
Anyway, you shouldn't be using malloc/free unless you absolutely can't
avoid them--use new/delete instead.
--
Dan Riley Internet: dsr@lns598.lns.cornell.edu
Wilson Lab, Cornell University HEPNET/SPAN: lns598::dsr (44630::dsr)
"Distance means nothing/To me." -Kate Bush
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1995-04-19 4:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-04-19 4:00 malloc() in /usr/include files Jon Howell
1995-04-19 4:00 ` Dan Pop
1995-04-19 4:00 ` Daniel S. Riley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox