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

Re: C++ question



Bryan Scaringe [bryan.scaringe@computer.org] wrote:
> It is my understandng that in order for C++ to "delete" a dynamically-allocated
> object, that object need to have been created via "new".
> 
> That said, I'd like to see the code where you do the allocation.

You are right. the memory allocation is done using calloc. Somthing like
this:
void    **new_hd = (void**)calloc(1, (list_count(l) + l->grow_size) * sizeof(void*));

So I replaced delete with free, and g++ seems happy again. But it still
fails with some of the warning messages.

Eg. if I compile with this:
$ g++ -g -c misc.c
misc.c: In function `char * cash(double, int, int)':
misc.c:44: implicit declaration of function `int bracket(...)'
misc.c:45: implicit declaration of function `int comma(...)'


The output is exactly the same with the newest g++ version, and older
g++. But the difference is that the older version will create a .o file
and the new version will not. And I can only see an error message when
they are compiled using make.


Shao.

> 
> Also, you may need to type-cast the void pointer.  The new compiler version
> may be more picky about that sort of thing (though if that's the case it should
> be a warning, not an error).
> 
> The comp.lang.c++ people will peobably be more helpful though.
> 
> If you do get a response, could you forward me a copy?  thanks.
> 
> Bryan
> 
> 
> On 15-Feb-2000 Shao Zhang wrote:
> > Hi, 
> >       I have posted this to comp.lang.c++, but hope someone here can
> >       help me as well. Thanks.
> > 
> > =====================
> >         I have a c++ program that compiles fine with
> >         earlier version of g++, but it no longer compiles with
> >         the newsest release 2.95.2.
> > 
> >         Here is the relevant bit of code:
> > 
> >         typedef struct List
> >         {
> >                 void            **hd;   /* first item */
> >                 void            **cr;   /* current item */
> >                 void            **tl;   /* last item */
> >                 void            **mx;   /* max item before growing is
> > required */
> >                 int             grow_size;
> >         } List;
> > 
> >         Some macros defined:
> > 
> >         #define fast_list_first(l)      ((l && l->hd)? *(l->cr = l->hd) : 0)
> >         #define fast_list_last(l)       ((l && l->hd)? *(l->cr = l->tl) : 0)
> > 
> >         And a Function like this:
> >         void lfree(List *l)
> >         {
> >                 void *item;
> >                 for (item=fast_list_first(l); item != NULL;
> > item=fast_list_last(l))
> >###->>>>                delete item;
> >         }
> > 
> > 
> >         When compiled with g++(2.95.2), it failed with this:
> >         [line 55 is the line marked with arrows above]
> >         % g++ -g -c misc.c
> >         misc.c: In function `void lfree(List *)':
> >         misc.c:55: warning: `void *' is not a pointer-to-object type
> > 
> >         It gives me the warning message, but no .o file is created, and
> >         if I put it in a makefile, it results:
> >         % make misc.o
> >         g++ -g -c misc.c
> >         misc.c: In function `void lfree(List *)':
> >         misc.c:55: warning: `void *' is not a pointer-to-object type
> >         make: *** [misc.o] Error 1
> > 
> > 
> >         Thanks for any help in advance.
> > 
> > Shao.
> > 
> > 
> > -- 
> > ____________________________________________________________________________
> > Shao Zhang - Running Debian 2.1  ___ _               _____
> > Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
> > University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
> > Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
> > Email: shao@cia.com.au                                                  |___/
> > _____________________________________________________________________________
> > 
> > 
> > -- 
> > Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org <
> > /dev/null
> 
> 

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


Reply to: