Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3065

Re: Compilers way to implement array allocations

From Pete Becker <pete@versatilecoding.com>
Organization Roundhouse Consulting, Ltd.
Newsgroups comp.lang.c++
Date 2011-04-03 20:25 -0400
Message-ID <2011040320254756281-pete@versatilecodingcom> (permalink)
References <xhnlp.1597$0j7.632@newsfe20.ams2> <c14c937c-5626-43cc-a0a6-06b743038e49@e21g2000yqe.googlegroups.com>
Subject Re: Compilers way to implement array allocations

Show all headers | View raw


On 2011-04-03 13:22:26 -0400, James Kanze said:

> On Apr 3, 6:35 am, Goran <goran.pu...@gmail.com> wrote:
>> On Apr 1, 7:32 pm, "crea" <n...@invalid.com> 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)

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Compilers way to implement array allocations "crea" <no@invalid.com> - 2011-04-01 17:44 +0100
  Re: Compilers way to implement array allocations Goran <goran.pusic@gmail.com> - 2011-04-01 10:19 -0700
    Re: Compilers way to implement array allocations Victor Bazarov <v.bazarov@comcast.invalid> - 2011-04-01 13:32 -0400
      Re: Compilers way to implement array allocations Goran <goran.pusic@gmail.com> - 2011-04-02 22:24 -0700
      Re: Compilers way to implement array allocations Virchanza <virtual@lavabit.com> - 2011-04-03 17:49 -0700
    Re: Compilers way to implement array allocations "crea" <no@invalid.com> - 2011-04-01 18:32 +0100
      Re: Compilers way to implement array allocations Victor Bazarov <v.bazarov@comcast.invalid> - 2011-04-01 13:52 -0400
      Re: Compilers way to implement array allocations Paavo Helde <myfirstname@osa.pri.ee> - 2011-04-01 13:29 -0500
        Re: Compilers way to implement array allocations "crea" <no@invalid.com> - 2011-04-01 20:10 +0100
          Re: Compilers way to implement array allocations Paavo Helde <myfirstname@osa.pri.ee> - 2011-04-01 14:56 -0500
      Re: Compilers way to implement array allocations Goran <goran.pusic@gmail.com> - 2011-04-02 22:35 -0700
        Re: Compilers way to implement array allocations "crea" <no@invalid.com> - 2011-04-03 14:55 +0100
        Re: Compilers way to implement array allocations James Kanze <james.kanze@gmail.com> - 2011-04-03 10:22 -0700
          Re: Compilers way to implement array allocations Pete Becker <pete@versatilecoding.com> - 2011-04-03 20:25 -0400
  Re: Compilers way to implement array allocations James Kanze <james.kanze@gmail.com> - 2011-04-03 10:15 -0700

csiph-web