From 5769297348037686822
X-Google-Thread: f78e5,60dc9044ee8e77d3,start
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news1.google.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: fedor_pikus@mentorg.com ("Fedor G. Pikus")
Newsgroups: comp.std.c++
Subject: Strange new/new() problem
Date: Mon, 17 Jan 2005 23:31:42 GMT
Lines: 49
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <41ec486b$1@solnews.wv.mentorg.com>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.demon.co.uk 1106004712 24070 158.152.254.254 (17 Jan 2005 23:31:52 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Mon, 17 Jan 2005 23:31:52 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-Trace: 17 Jan 2005 15:21:15 -0800, lorien.wv.mentorg.com
X-User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.5) Gecko/20041221 MultiZilla/1.7.0.0o
X-Accept-Language: en-us, en
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
X-Original-NNTP-Posting-Host: lorien.wv.mentorg.com
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id j0HNVgmJ020362;
	Tue, 18 Jan 2005 10:31:42 +1100 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:3899

I've run into a little problem with operator new.
Consider this example:
struct data
{
     int i;
     int j;
};
int main()
{
     data** p = new (data*)[5];
}

What the programmer wanted is to allocate an array of pointers, of 
course, and the parenthesis are unnecessary but arguably make reading 
the code easier.

GCC compiled the code just fine, and did what the programmer wanted, but 
several other compilers refused. Error messages are of two types: either 
it's "cannot assign data* to data**" or "[5] is unexpected". Comeau 
falls into the first cathegory, and I usually trust Comeau to get it 
right. Both messages suggest that these compilers interpret this code as 
the placement new with "data *" being the location, even though it's a 
type, not a variable.

Just for kicks, I tried this modification:
data* p1 = new (data*)[5];
on some of the compilers which complained about pointer conversion, and 
now the compilers are happy, program runs, and p is NULL.

So, is the above (topmost) example legal in C++ or parenthesis are 
actually wrong, not just unnecessary?

Is the modification legal in C++ (Comeau says yes)? If the p1 line is 
legal, what is it doing, how is it parsed? "data*" is a location 
argument to placement new? What't the type then?
-- 
                                   Fedor G. Pikus
http://www.pikus.net/~pikus/

Mentor Graphics Corporation         | Phone: (503) 685-4857
8405 SW Boeckman Road               | FAX:   (503) 685-1239
Wilsonville, Oregon 97070           |

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



