Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!ames!sgi!shinobu!odin!delrey!shap From: shap@delrey.sgi.com (Jonathan Shapiro) Newsgroups: comp.lang.c++ Subject: Re: unbounded static array member Message-ID: <5104@odin.SGI.COM> Date: 9 Mar 90 23:47:03 GMT References: <11024@saturn.ucsc.edu> Sender: news@odin.SGI.COM Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 45 In article <11024@saturn.ucsc.edu> daniel@saturn.ucsc.edu (Daniel Edelson) writes: >Is there or should there be a syntax for declaring a static array >member whose length is determined by the length of its initializer list? > >e.g., > > struct S > static int array[]; // Error, bound required > }; > > int S::array[] = { 1, 2, 3, 0}; No. Such an array is not (by definition) fixed size given only the declaration to work from. In C/C++, that's what pointers are for. What IS needed is a way to define class objects that act like arrays. These need a suitable constructor that is not now found in the language for static initialization: class Foo; class FooArray { ... public: FooArray[](int, const Foo *const); }; FooArray myFooArray = { foo, foo, foo, foo, foo }; The claim is that we should model the array initialization syntax as a pair of the form (length, pointer-to-base) In the absence of this one cannot build things like static bounds-checked arrays that are initialized without introducing extra variables. On the other hand, it's definitely a marginal problem, and this idea is at best half-baked. Jonathan Shapiro Silicon Graphics