🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #2038

Re: Should I learn C or C++ first?

#2038
From: Rainer Deyke
Date: Fri, 01 Sep 1995 13:06
49 lines
2640 bytes
Pete Becker (pete@borland.com) wrote:
: In article <41tjep$2hn@deyke3.fc.hp.com>, rainer@deyke3.fc.hp.com says...
: >
: >Pete Becker (pete@borland.com) wrote:
: >: In article <41kici$p4t@deyke3.fc.hp.com>, rainer@deyke3.fc.hp.com says...
: >: >Why bother with doing both at the same time?
: >: >
: >: >MyApp = (TApplication *)malloc(sizeof(TApplication));
: >: >create_TApplication(MyApp, "My Application");
: >
: >: The difference is in the gap between the two lines, where you have 
: something 
: >: that claims to be a pointer to a TApplication object, but isn't. C++ makes 
: it 
: >: very hard to perform operations on objects that have not been initialized. 
: >: Separating memory allocation from initalization makes it much easier to 
: >: accidentally do things like this, as we have all done at one time or 
: another.
: >
: >Real programmers don't "accidentally" forget to initialize objects.
: >

: Real programmers are human and make mistakes.

There are hundreds of more likely mistakes.

: >:       Or, to turn the question around the other way, why separate them?
: >
: >Obviously when using an array where each object is initialized to a
: >different value.  Especially a resizable array.

: That's not the example you posted, which allocated a single object. So, let me 

The example I posted was only the example you posted adjusted to use
malloc.  Of course there's no advantage in malloc here but there's no
disadvantage either.

: ask again: in the code you posted, what benefit is there in separating 
: allocation from initialization?

None.  However, how would you add three objects to a dynamic array
(allocated using new) of ten objects, intializing each of the new
members to a random number (using rand())?

--
+----------------------------------------------+
|    Rainer Deyke (rainer@mdddhd.fc.hp.com)    |
| "The Earth shall inherit the meek" - Carcass |
+----------------------------------------------+
Technical Details
Message-ID: <4270gf$gmm@deyke3.fc.hp.com>
Path: arc1-ca.pugleaf.net!fc.hp.com!hpfcmdd!deyke3!rainer
References: <DDJ2Lp.3DG@pentagon-ai.army.mil> <41afe9$d10@newsbf02.news.aol.com> <41kici$p4t@deyke3.fc.hp.com> <41ngln$qau@druid.borland.com> <41tjep$2hn@deyke3.fc.hp.com> <41vlgv$q33@druid.borland.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fc.hp.com!hpfcmdd!deyke3!rainer
From: rainer@deyke3.fc.hp.com (Rainer Deyke)
Newsgroups: rec.games.programmer,comp.lang.c++
Subject: Re: Should I learn C or C++ first?
Followup-To: rec.games.programmer,comp.lang.c++
Date: 1 Sep 1995 13:06:23 GMT
Organization: my basement
Message-ID: <4270gf$gmm@deyke3.fc.hp.com>
References: <DDJ2Lp.3DG@pentagon-ai.army.mil> <41afe9$d10@newsbf02.news.aol.com> <41kici$p4t@deyke3.fc.hp.com> <41ngln$qau@druid.borland.com> <41tjep$2hn@deyke3.fc.hp.com> <41vlgv$q33@druid.borland.com>
Reply-To: rainer@mdddhd.fc.hp.com
NNTP-Posting-Host: deyke3.fc.hp.com
X-Newsreader: TIN [version 1.2 051093BETA PL3]