From 8571467460851687757
X-Google-Thread: f78e5,60dc9044ee8e77d3
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news2.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: comeau@panix.com (Greg Comeau)
Newsgroups: comp.std.c++
Subject: Re: Strange new/new() problem
Date: Sat, 22 Jan 2005 03:47:55 GMT
Organization: Comeau Computing; http://www.comeaucomputing.com
Lines: 72
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <csr7af$5i9$1@panix1.panix.com>
References: <41ec486b$1@solnews.wv.mentorg.com>
NNTP-Posting-Host: news.news.demon.net
X-Trace: news.demon.co.uk 1106365679 5026 158.152.254.254 (22 Jan 2005 03:47:59 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sat, 22 Jan 2005 03:47:59 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
X-Reply-To: comeau@comeaucomputing.com
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id j0M3ltBS012359;
	Sat, 22 Jan 2005 14:47:55 +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++:3937

In article <41ec486b$1@solnews.wv.mentorg.com>,
Fedor G. Pikus <fedor_pikus@mentorg.com> wrote:
>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.

That does not request an array of pointers.  These don't work as decls:

(data *)p[5];
(data *p2)[5];

An array of pointers to data is 'data *[5]'

>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.

It's not being interpreted as a placement new, but as a 'new data *'

>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,

But the program is still wrong.

>program runs,

Well, at least does not fail.

>and p is NULL.

Appears to be thus far in your tests.

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

Wrong IMO.

>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?

You've sub-expressions, starting with 'new data *'.
-- 
Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
Comeau C/C++ ONLINE ==>     http://www.comeaucomputing.com/tryitout
World Class Compilers:  Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

---
[ 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                       ]



