From: dsr@lns598.lns.cornell.edu (Daniel S. Riley)
Subject: Re: malloc() in /usr/include files
Date: 1995/04/19 [thread overview]
Message-ID: <DSR.95Apr19153815@lns100.lns.cornell.edu> (raw)
In-Reply-To: Pine.OSF.3.91.950419104826.8485M-100000@stout.hitl.washington.edu
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
next prev parent reply other threads:[~1995-04-19 4:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-04-19 4:00 malloc() in /usr/include files Jon Howell
1995-04-19 4:00 ` Daniel S. Riley [this message]
1995-04-19 4:00 ` Dan Pop
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox