Article View: comp.std.c++
Article #3458Re: Correctness of compilers behavior
From: Tilo Koerbs
Date: Thu, 15 Feb 1996 15:42
Date: Thu, 15 Feb 1996 15:42
26 lines
1716 bytes
1716 bytes
The array is created using 'new B[...]'. The SPARCompiler stores
additional information when creating an array. This is neccessary
in C++ to be able to call the destructor for all elements of the
array on 'delete []'. At least it needs to store the number of elements
of the array and the size of an individual element.
( class X {};
class Y : public X {};
y = new Y[..];
delete [] (X*)y; // sizeof(X) may be unequal to sizeof(Y);
)
So the SPARCompiler also stores the information, which destructor to invoke!
You can cast the pointer obtained from 'new B[...]' as often as you want
and you can write code into your array as much as you want,
the compiler uses the additional information stored with 'new B [...]'
to destruct the array. And this information says: IT IS A 'B' ARRAY!
The code you wrote is simply not portable.
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
]
Technical Details
Message-ID:
<4fv5cb$9oj@fsuj01.rz.uni-jena.de>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<3122157A.2EB2@orbotech.co.il>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs) Newsgroups: comp.std.c++ Subject: Re: Correctness of compilers behavior Date: 15 Feb 1996 15:42:47 GMT Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <4fv5cb$9oj@fsuj01.rz.uni-jena.de> References: <3122157A.2EB2@orbotech.co.il> Reply-To: mkt@isun04.inf.uni-jena.de NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: isun07.inf.uni-jena.de Content-Length: 838 X-Lines: 21 Originator: clamage@taumet