🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2723

Re: Array Initialization

#2723
From: rjl
Date: Fri, 24 Nov 1995 17:24
54 lines
2747 bytes
In article <DIHM2v.2Av@cadlab.it>, Alex Martelli <martelli@cadlab.it> wrote:
:>IMHO that is not acceptable because in
:>portable code you would not know whether a declaration like
:>	char buffer[length];
:>could fail.
:
:But that would be no different from the present situation!  I.e., in
:portable code you DO not know whether a declaration like
:	char buffer[16384];
:can fail; it depends on whether your current stack has space for
:it, on whether the OS can extend that stack dynamically for you,
:etc, etc.  And, if it does fail, there's no *portable* way to
:catch it, either.

The problem is more complex than this.  Imagine how unorthogonal it is
if you can make automatic array variable sized, but why then can't
an array in a class be made like this ? (Yes I know the reason, I'm
trying to point out the real problem).

eg.
  class Foo {
    const int X;
    int Bar[X];
  public:
    Foo() : X(10) { /* Array is size ten in here */ };
  };

I'm all for nifty features, but not at the expense of orthogonality.  You
then end up with nasty kludges.

There is *no* prior art for this.

:>You can get the effect you want by using an auto_ptr and heap allocation,
:
:auto_ptr does not handle builtin arrays, so how could it ever help here?
:If you new[] some memory, you cannot use the resulting pointer to an
:auto_ptr nor any other standards-supplied class -- you have to use a
:bare pointer, or roll-your-own -- in which latter case the following
:idea appears much more promising:
:

Why is there no auto_array_ptr in the DWP ? Is it an omission or a mistake ?

Regards,
	Rohan
-- 
----------------------------------------------------------------------------
rjl@iassf.easams.com.au	| All quotes can be attributed to my automated quote
Rohan Lenard            | writing tool.  Yours for just $19.95; and if you
+61-2-367-4555          | call now you'll get a free set of steak knives ...

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <199511240018.AA20581@hercules.iassf.easams.com.au>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <30B1CB7E.41C67EA6@ecid.cig.mot.com> <48t9t7$5c2@engnews1.eng.sun.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: rjl@iassf.easams.com.au
Newsgroups: comp.std.c++
Subject: Re: Array Initialization
Date: 24 Nov 1995 17:24:28 GMT
Organization: EASAMS (Australia) Pty Ltd
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <199511240018.AA20581@hercules.iassf.easams.com.au>
References: <30B1CB7E.41C67EA6@ecid.cig.mot.com> <48t9t7$5c2@engnews1.eng.sun.com>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
In-Reply-To: <DIHM2v.2Av@cadlab.it>
Cc: martelli@cadlab.it
Content-Length: 1899
Originator: clamage@taumet