Results 1 to 3 of 3

Thread: could u please say what is the real usage of "Unions" in C

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    could u please say what is the real usage of "Unions" in C

    Hi All,

    I know unions(in c language) little bit. memory allocation for a variable of union depends on the memory of a field,which is occupying highest memory rather than other fields. so if we try to read the data to all the fileds in a union, it may cause to data violation.

    Then what is the real usage of the Union? if u say a real example.. it will be more helpful to me.

    Thanks:
    regards:
    raghunadhs

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: could u please say what is the real usage of "Unions" in C

    Really, with todays PC's, theres no need to use unions. My tutor at school said he had to use them for the PS2 to save as much space as possible (which was part of their design). Since the members of a union, start at the exact same address, it saves space by having them all in the one section, rather than spread out to the size of each type.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Posts
    167

    Re: could u please say what is the real usage of "Unions" in C

    Hi ChemicalNova,
    But i heared that this union cocept will be very useful,in embeded environ ment, to reduce the memory occupation.... but i don't know how to use in real time.
    Thanks for u r reponse.
    Thanks,
    regards:
    raghunadhs

    Quote Originally Posted by chemicalNova
    Really, with todays PC's, theres no need to use unions. My tutor at school said he had to use them for the PS2 to save as much space as possible (which was part of their design). Since the members of a union, start at the exact same address, it saves space by having them all in the one section, rather than spread out to the size of each type.

    chem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width