[ub] Type punning to avoid copying
Gabriel Dos Reis
gdr at cs.tamu.edu
Fri Jul 26 18:23:22 CEST 2013
Jeffrey Yasskin <jyasskin at google.com> writes:
| On Fri, Jul 26, 2013 at 9:10 AM, Gabriel Dos Reis <gdr at cs.tamu.edu> wrote:
| > Jeffrey Yasskin <jyasskin at google.com> writes:
| >
| > | On Fri, Jul 26, 2013 at 8:30 AM, Gabriel Dos Reis <gdr at cs.tamu.edu> wrote:
| > | > Ion Gaztañaga <igaztanaga at gmail.com> writes:
| > | >
| > | > [...]
| > | >
| > | > | ¿How can we tell the compiler that a memory buffer is really a different
| > | > | type?
| > | >
| > | > Invoke a constructor to turn the raw memory into an object of the
| > | > desired type.
| > |
| > | Can you point to the wording that explains the behavior in that case?
| >
| > I am not sure I understand your request. Ion wants to state a region of
| > storage is of a given type. The behavior after the contructor ran is
| > what you get after running a constructor -- see section 12.1.
|
| Yeah, sorry. I mean, if I write:
|
| float f = 3.2f;
| int* i = new(&f) int;
| use(*i);
|
| where does it say what the value of '*i' is? I'm expecting
| implementation-defined, but I don't know exactly where to look.
|
| Thanks,
| Jeffrey
The object at 'i' is constructed but not initialized, so its value is
indeterminate. See 5.3.4/15.
-- Gaby
More information about the ub
mailing list