Unions. Except from Memory allocation do they have any difference from Structures?

This is a discussion on Unions. Except from Memory allocation do they have any difference from Structures? within the C Programming forums, part of the General Programming Boards category; Is there any difference in unions from structures - except than memory allocation ?...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Location
    Greece
    Posts
    32

    Unions. Except from Memory allocation do they have any difference from Structures?

    Is there any difference in unions from structures - except than memory allocation ?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,742
    No.

    Did you have something specific in mind?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Greece
    Posts
    32
    Its just that they appeared like twins to me.

    Thank you.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    7
    No. Only difference between union and structure is the way they get stored in memory.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    I can't recall the behaviour of objects with constructors etc in a union, but basically don't do it anyway.
    Not sure if you can inherit from them either.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,112
    Not sure if you can inherit from them either.
    I am sure that you cannot inherit from structs and unions
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by laserlight View Post
    I am sure that you cannot inherit from structs and unions
    In C, I would agree. If we expand to C++, you can inherit a struct, but not a union.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory allocation from stack and heap ?
    By Bargi in forum C++ Programming
    Replies: 5
    Last Post: 05-29-2008, 01:37 AM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 08:54 AM
  3. memory allocation ptr to array? how?
    By kokopo2 in forum C Programming
    Replies: 8
    Last Post: 09-01-2005, 06:06 PM
  4. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 07:45 PM
  5. Structures - Unions
    By AProg in forum C Programming
    Replies: 16
    Last Post: 05-27-2003, 01:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21