Accessing member of non-lvalue union

Discussion in 'C Programming' started by Johannes Schaub (litb), Nov 13, 2010.

  1. 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.
    Johannes Schaub (litb), Nov 13, 2010
    #1
    1. Advertising

  2. "Johannes Schaub (litb)" <> writes:

    > 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.

    --
    Ben.
    Ben Bacarisse, Nov 13, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kavya
    Replies:
    9
    Views:
    507
    Dik T. Winter
    Oct 28, 2006
  2. Andrew Ward
    Replies:
    2
    Views:
    1,042
    Zorro
    Jul 19, 2005
  3. Replies:
    9
    Views:
    946
    Ben Bacarisse
    Feb 6, 2006
  4. Replies:
    11
    Views:
    693
    James Kuyper
    Sep 22, 2008
  5. Julian Mehnle
    Replies:
    0
    Views:
    238
    Julian Mehnle
    Jul 17, 2003
Loading...

Share This Page