Path: utzoo!attcan!uunet!samsung!usc!orion.oac.uci.edu!uci-ics!rfg From: rfg@ics.uci.edu (Ronald Guilmette) Newsgroups: comp.lang.c++ Subject: Re: The type yielded by "new T[expression]" Message-ID: <2607D2AE.14933@paris.ics.uci.edu> Date: 21 Mar 90 19:14:55 GMT References: <26068361.27247@paris.ics.uci.edu> <10605@alice.UUCP> Reply-To: rfg@ics.uci.edu (Ronald Guilmette) Organization: UC Irvine Department of ICS Lines: 53 In article <10605@alice.UUCP> ark@alice.UUCP (Andrew Koenig) writes: >In article <26068361.27247@paris.ics.uci.edu>, rfg@paris.ics.uci.edu (Ronald Guilmette) writes: > >> Currently (it seems) the value yielded by an "array new" operation like >> this is treated as being of type "pointer-to-T". This seems highly >> nonsensical to me. It would make far more sense if the type of value >> yielded were "pointer-to-array-of-T" when the "new" invocation includes >> a (square-bracketed) size expression. > >Impossible, because `size' doesn't need to be a constant. It is most definitely *not* impossible as you claim. I believe that you are assuming that any "pointer-to-array" type must be a "pointer-to-bounded- array" type. This is *not* true. For example, what I proposed was to allow: typedef T array_of_T[]; // unspecified bound void foo () { array_of_T *p; // already perfectly legal! p = new T[100]; } In effect, I'm suggesting that the type of value returned by "new T[size]" be "pointer-to-GENERIC-array-of-T" not "pointer-to-SPECIFIC-array-of-T". As noted above, such "generic array" types already exist in the language. Admitedly, you cannot just declare objects of "generic" (or "unbounded") array types, but you can point to (and refer to) such objects using pointers like the variable "p" declared in the example above. >If you want a pointer to array of, say, 17 T, you can write > > new T[17][1] > >which will get you exactly that. Thanks Andrew, but I wasn't looking for a workaround. I was just suggesting that there exists an unnecessary hole in the C++ type system, and I was suggesting a simple way to fix it. P.S. I appologize to all for the unnecessary arrogance of my prior posting. I lose my perspective sometimes and I forget that language issue are not worth going to war over. Everyone should feel free to kick me if I forget again. // Ron Guilmette (rfg@ics.uci.edu) // C++ Entomologist // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.