Thread: union problems return

  1. #1
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001

    union problems return

    ok let say i have a union called "shareLD" which takes this form:

    union shareLD
       double dval;
       long lval;
    shareLD myUnion;
    myUnion.dval = 3.5;
    so now dval contains 3.5...i get that part...but does lval contain 3.0 since they share the same memory?

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    >>but does lval contain 3.0 since they share the same memory?
    No, you can only use one member at a time in a union.

  3. #3
    Join Date
    Aug 2001
    Groningen (NL)
    You can use both members at same time. The problem here is that double is not an int-type. If you had for example the following union:

    union myunion
        int a;
        int b;
    Now if you have a variable of type myunion and assign a value x to variable a, then b has the same value as a. They share the same memory.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New string functions
    By Elysia in forum C Programming
    Replies: 11
    Last Post: 03-28-2009, 05:03 AM
  2. DirectInput help
    By Muphin in forum Game Programming
    Replies: 2
    Last Post: 09-10-2005, 11:52 AM
  3. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM