cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/27/17:02:11

From: mstensho AT powertech DOT no (Morten Stenshorne)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: keyword "new" causes SIGSEV
Date: Tue, 25 Aug 1998 20:50:15 GMT
Organization: Pinkadux sukkerfrie skrusokker
Lines: 53
Sender: mstensho AT vangelis DOT dyn DOT ml DOT org
Message-ID: <c0.9w.2MdmRW$05q@vangelis.dyn.ml.org>
References: <35E1C842 DOT 45EFF366 AT newnorth DOT net>
Reply-To: mstensho AT powertech DOT no (Morten Stenshorne)
NNTP-Posting-Host: s01i21-0004.no.powertech.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In <35E1C842 DOT 45EFF366 AT newnorth DOT net>, Mike Rusch <ruschtmm AT newnorth DOT net> writes:
>In my program, I define a structure reptfmt as follows:
>
>struct reptfmt {
>    char numfields;
>    char numsorts;
>    char **fnames;
>    fieldinfo *fields;
>    sortinfo *sorts;
>    char groups;
>} ;

You forgot to tell us what "sortinfo" and "fieldinfo" is. I assume they are ints, just
like what any tolerant compiler would do... :)
If these datatypes are more complex than that, I would like to know.

> [...]

Your code worked fine here, both with GCC for DJGPP and GCC for EMX (OS/2).
Borland C++ 3.1 for DOS gave me compiler errors (!).
But I think that is Borland's fault.

How does your code that calls reptfmtcpy() look like? Maybe you're doing
something strange there? 
As far as I can see, your code looks OK.

>Sometimes I need a copy of a reptfmt structure.  Since var1 = var2
>doesn't make copies of the data pointed to by fnames, fields, and sorts,
>I had to write a special function called "reptfmtcpy":

I would rather advise you to make a class, instead of a struct, and then make
a copy constructor.

>So, what do I do?  From the traceback it almost looks like "new" calls
>malloc, but this seems strange to me since new is supposed to be a
>keyword, and supposedly more efficient than malloc.  I suppose I could
>use malloc instead, but then I'd have to change all my new's to malloc's
>and my delete's to free's.  Plus, who knows if malloc would work any
>better?

I've never heard that "new" should be more efficient than malloc(). I beleive
that "new" was invented in order to make memory allocation a part of the 
C++ language, not just a library function. It made it easier for the programmer, 
but program execution hasn't necessarily become more efficient.
Am I wrong?

--

 ---- Morten Stenshorne, Gommerud, 3320 Vestfossen, NORWAY  ----
-- mstensho AT powertech DOT no -- http://home.powertech.no/mstensho/ --
 ---- Computer Engineer -- Phone: 93440112 -- Doofuz AT IRCNet ----

Veni, vedi, VISA - I came, I saw, I bought.

- Raw text -


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