"ian at airs dot com" <[EMAIL PROTECTED]> writes:

| But I don't think that is the question at hand.  The variable is always being
| accessed in the same type, which is also the type of its declaration.  The
| question at hand is this:
| 
| void f(double* p) { *(int*)p = 3; long *l = new (p) long; *l = 4; }
| void g() { int i; f((double *)&i); }
| 
| And the specific question is whether we are permitted to interchange the
| assignments to *p and *l.

After the placement new, the lifetime of *p is ended, and the lifetime
of *l starts there.  I don't think that leaves room for exchanging the
stores to *p and *l.

| Let's consider this:
| 
| void f(double* p) { *(int*)p = 3; long *l = (long*)p; *l = 4; }
| 
| Is that valid?

If p is pointing to a union object that contain both int and long,
yes, it is valid.  Otherwisem, it is not.

|  Is the compiler permitted to interchange the assignments to *p
| and *l?

It is valid if we have a union object, otherwise, no.

-- Gaby

Reply via email to