[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Texmacs-dev] Applied patches
From: |
david |
Subject: |
Re: [Texmacs-dev] Applied patches |
Date: |
Sun, 19 Jan 2003 17:30:55 +0100 |
User-agent: |
Mutt/1.4i |
On Sat, Jan 18, 2003 at 12:49:01PM +0100, Joris van der Hoeven wrote:
>
> > > 951: Applied
> >
> > This patch is wrong and should be unapplied.
>
> OK, I did that.
>
> > The correct fix is to remove the uneeded (and seemingly wrong)
> > parenthesis in the type-id of new.
>
> I am not sure that I understand what you propose.
>
> tree** rs= new (tree*)[nr_rows];
>
> by
>
> tree** rs= new tree* [nr_rows];
Yes. In a recent answer to you on this mailing list, I said:
> > 6. A few (2 or 3) explicit casts to type (X**) for the
> > result of a "new (X*) [...]" operation to work around an
> > apparent bug in our > > 7.4 compilers (I've also given
> > notice about this to our C++ front-end > > engineers). > >
> > No problem; we will correct that too.
I am unsure that is really a compiler problem, and unsure the fix
is right. For the record, the original code looks like:
tree** rs= new (tree*)[nr_rows];
ISO C++, section 5.3.4 [expr.new], clause 5:
When the allocate object is an array (that is, the
/direct-new-declarator/ syntax is used or the /new-type-id/ or
/type-id/ denotes an array type, the /new-expression/ yields a
pointer to the initial element (if any) of the array [Note: both
'new int' and 'new int[10]' have type 'int*' and the type of
'new int[i][10]' is 'int (*)[10]'.]
That means that no cast (implicit or explicit) should be involved
in this statement.
In ISO C++ section 5.3.4 [expr.new], clauses 1, 2 et 3 one see
that parenthesis in new-expressions can have suprising effects. It
seems that in that code (tree*) may be interpreted as a
parenthesised type-id and [nr_rows] as a new_initializer (which
would yield a syntax error). Actually the standard seems a bit
ambiguous on that point, which would explain that different
compilers behave differently.
What is the actual error you are getting from your compiler?
Actually it seems that tree*[nr_rows] effectively means 'array of
nr_rows pointers to tree'. So the following is correct:
tree** rs= new tree*[nr_rows];
A similar example is given in section 8.1 [dcl.name].
Actually, it does not even seems that the seemingly unambiguous
tree** rs= new ((tree*)[nr_rows]);
is correct.
I admit that if you read mail *very* quickly, you may misunderstand
what I just said here.
If one want to avoid type-id syntax, one should instead use
typedef.
The "seemingly" came from some experiments I made with the program
c++decl:
c++decl> explain (int*[])i
cast i into array of pointer to int
c++decl> explain ((int*)[])i
parse error
--
David Allouche | GNU TeXmacs -- Writing is a pleasure
Free software engineer | http://www.texmacs.org
http://ddaa.net | http://alqua.com/tmresources
address@hidden | address@hidden
TeXmacs is NOT a LaTeX front-end and is unrelated to emacs.