Accessing member of non-lvalue union

  • Thread starter Johannes Schaub (litb)
  • Start date
J

Johannes Schaub (litb)

This seems to be fine according to rules, right? (assuming that we won't
create a trap representation)

union A {
int i;
float d;
};

union A f() {
union A a = { 10 };
return a;
}

int main() {
// note: we don't access an object and don't use lvalues!
float ff = f().d;
}

I wonder whether this is fine.
 
B

Ben Bacarisse

Johannes Schaub (litb) said:
This seems to be fine according to rules, right? (assuming that we won't
create a trap representation)

union A {
int i;
float d;
};

union A f() {
union A a = { 10 };
return a;
}

int main() {
// note: we don't access an object and don't use lvalues!
float ff = f().d;
}

I wonder whether this is fine.

I can't see anything wrong with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top