Path: utzoo!attcan!uunet!snorkelwacker!usc!orion.oac.uci.edu!uci-ics!gateway From: rfg@paris.ics.uci.edu (Ronald Guilmette) Newsgroups: comp.lang.c++ Subject: The type yielded by "new T[expression]" Message-ID: <26068361.27247@paris.ics.uci.edu> Date: 20 Mar 90 19:24:18 GMT Organization: UC Irvine Department of ICS Lines: 60 I believe that there exists a ghastly violation of strong typing rules currently built into the C++ language. I'd like somebody to explain this to me and defend it (if possible). First, some background. Note that a type which is "pointer-to-T" is very different from a type which is "pointer-to-array-of-T". If you don't believe it, just try compiling this: int *ip; int (*iap)[]; void foo () { ip = iap; // gets error iap = ip; // gets error; } Now the question I'm concerned about is: "What is the type of the value yielded by: new T[size]; 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. Does anyone disagree? If so, please state your reasoning. One minor footnote. It was formerly the case that any attempts to "delete" arrays of objects had to include a square-bracketed size expression in the delete statement, i.e.: delete [size] ptr; It appears that this has changed recently, and that the proper way to do this now is simply: delete [] ptr; This also appears highly nonsensical to me. Why not just allow typing information to determine the type of delete operation to be performed. For example, if the type of "ptr" is "pointer-to-T" then the statement: delete ptr; would delete a single object (as has traditionally been the case). However if the type of "ptr" is "pointer-to-array-of-T", then: delete ptr; would (obviously) need to delete an array of objects. Am I making too much sense? // Ron Guilmette (rfg@ics.uci.edu) // C++ Entomologist // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.