NetBSD-Help archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: free in C++?

Martijn van Buul wrote:
> > The free manpage indicates this is a libc diagnostic.  Trying to
> > follow directions, I put 
> >
> >     extern char *malloc_options;
> The manpage calls for _malloc_options. Note the leading underscore.
> Also, since you're calling this from C++, you will need to explicitly
> tell it to use C linkage. This is not a NetBSD issue, but a C-vs-C++
> issue.
> try
> extern "C" char *_malloc_options;
> char *_malloc_options = "X";

Well, that's odd.  I suppose I should have mentioned

        $ uname -sr && c++ -v 2>&1 | grep version
        NetBSD 2.0
        gcc version 3.3.3 (NetBSD nb3 20040520)

My libc agrees with my man page and has no leading underscore:

$ nm /usr/lib/libc.a | grep malloc_options
00000004 C malloc_options

I tried your suggestion and got:

/usr/include/g++/bits/stl_deque.h:1065: undefined reference to

AFAIK your point about external linkage applies only to functions, not
global (file-scope) variables, because only functions have mangled names. 
I found using getopt(3) from a C++ function I can *not* declare e.g.
optarg as extern "C".  

I suppose this is really a gcc question; I just hoped to get lucky here.  


Home | Main Index | Thread Index | Old Index