Article View: comp.std.c++
Article #2677Re: Array Initialization
From: Steve Clamage
Date: Wed, 22 Nov 1995 03:21
Date: Wed, 22 Nov 1995 03:21
35 lines
2165 bytes
2165 bytes
In article 41C67EA6@ecid.cig.mot.com, Joe Walker <walkerjj@ecid.cig.mot.com> writes: >Has allowing the following been considered? > > int length = strlen (some_string); > char buffer [ length ]; > >I.E. allowing non const array sizing. It is not supported by the C++ draft standard for the same reason it is not supported by the C standard. It would mean in particular for auto arrays that the size of the stack frame could not be known until a function was entered, and could be different at each invocation. On some platforms that is not a problem. On others it is difficult to implement, or forces function calls to be much more expensive, or violates the ABI. For static arrays, some object formats require the array size to be specified at link time and not deferred until run time. The standard could say that an implemention is allowed to simulate variable-sized stack or static arrays by using the heap and automatically deallocating the storage. IMHO that is not acceptable because in portable code you would not know whether a declaration like char buffer[length]; could fail. It also could turn what looks like a simple declaration into a heavy-weight operation. You can get the effect you want by using an auto_ptr and heap allocation, or by using an array class instead of a C-style array. --- Steve Clamage, stephen.clamage@eng.sun.com --- [ 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:
<48t9t7$5c2@engnews1.eng.sun.com>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<30B1CB7E.41C67EA6@ecid.cig.mot.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 22 Nov 95 03:21:23 GMT Approved: fjh@cs.mu.oz.au From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Array Initialization X-Original-Date: 21 Nov 1995 19:39:19 GMT Organization: Sun Microsystems Inc. Message-ID: <48t9t7$5c2@engnews1.eng.sun.com> References: <30B1CB7E.41C67EA6@ecid.cig.mot.com> Reply-To: clamage@Eng.Sun.COM X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMLKXQ+EDnX0m9pzZAQHz3AF+O8bTFbQICjtftnGxwSaGl1xQewEUqIIA vnljWsiCzhfAU5vXwakLoeVnY+wOTOtf =97sA