Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin1!goblin.stu.neva.ru!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 03 Apr 2011 19:25:46 -0500 From: Pete Becker Organization: Roundhouse Consulting, Ltd. Newsgroups: comp.lang.c++ Date: Sun, 3 Apr 2011 20:25:47 -0400 Message-ID: <2011040320254756281-pete@versatilecodingcom> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: Compilers way to implement array allocations User-Agent: Unison/2.1.4 Lines: 35 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-3MK/lRDCVIcsQzDaoUZw3rd0aLZ9/I2135j3WFaWdzqpurVW4sBlu/9Gf+tSUoRCcPb9mOp/5z4BxXI!Rkvnfi0GeZBai2q5O+jy02hzVRGs82JDQosgqEr4MUGwvkQHKgmojKc9dSrJB/QhIeZJxnJu X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2210 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:3065 On 2011-04-03 13:22:26 -0400, James Kanze said: > On Apr 3, 6:35 am, Goran wrote: >> On Apr 1, 7:32 pm, "crea" wrote: > > [...] >>> So my question is, that why cant I destroy this automatic >>> object? How/why does the compiler prevent that? > >> Compiler does not prevent it. For example: > >> void f() >> { >> int i; // automatic >> int* p = &i; >> delete p; // boom >> } > >> This code is 100% legal, and compiler will compile it without any >> complaint. But at runtime, boom! > > The code is not "legal" (for the usual definition of legal). It > has undefined behavior. One possible behavior is that the > compiler refuse to compile it, or issues an error message. > Another is that something strange happens at runtime. > And a third is that it will "work just fine". Until it doesn't. -- Pete Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The Standard C++ Library Extensions: a Tutorial and Reference (www.petebecker.com/tr1book)