Design decisions on data structures

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asm

    #1

    Design decisions on data structures

    Hi All,

    I would like to know what should be the criteria to choose between a
    union / structure. Also switch statement vs if - else. I know switch
    only 'switches' on
    integer types. Some example would be of help.

    Thanks,
    ASM
  • Jack Klein

    #2
    Re: Design decisions on data structures

    On 4 Oct 2004 04:16:54 -0700, arut@post.com (asm) wrote in
    comp.lang.c:
    [color=blue]
    > Hi All,
    >
    > I would like to know what should be the criteria to choose between a
    > union / structure. Also switch statement vs if - else. I know switch
    > only 'switches' on
    > integer types. Some example would be of help.
    >
    > Thanks,
    > ASM[/color]

    Unions and structures are very different things. A structure always
    has the same type of contents and those contents can consist of many
    different data types. A union can contain different data types, but
    only one of them at a time.

    If you don't know of any reasons why you should use unions, then you
    most surely should use structures.

    As for "if...else if...else" rather than switch statements, use
    whichever one makes your code clearer. Generally, if there are more
    than three possibilities and they are all based on the value of an
    integer object, that means using switch.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.l earn.c-c++

    Comment

    Working...