Order of structure members in memory

Discussion in 'C Programming' started by Christopher Benson-Manica, Sep 26, 2004.

  1. Are the members of a struct guaranteed to have ascending memory
    addresses?

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Sep 26, 2004
    #1
    1. Advertising

  2. Christopher Benson-Manica

    Ben Pfaff Guest

    Christopher Benson-Manica <> writes:

    > Are the members of a struct guaranteed to have ascending memory
    > addresses?


    Yes.
    --
    "A lesson for us all: Even in trivia there are traps."
    --Eric Sosman
     
    Ben Pfaff, Sep 26, 2004
    #2
    1. Advertising

  3. Christopher Benson-Manica

    Jack Klein Guest

    Jack Klein, Sep 26, 2004
    #3
  4. Jack Klein <> spoke thus:

    > Yes, always in C.


    Just for my edification, what is the chapter and verse? Thanks...

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Sep 26, 2004
    #4
  5. Christopher Benson-Manica

    Eric Amick Guest

    On Sun, 26 Sep 2004 20:07:47 +0000 (UTC), Christopher Benson-Manica
    <> wrote:

    >Jack Klein <> spoke thus:
    >
    >> Yes, always in C.

    >
    >Just for my edification, what is the chapter and verse? Thanks...


    In C99, it's 6.7.2.1, paragraph 13.

    --
    Eric Amick
    Columbia, MD
     
    Eric Amick, Sep 26, 2004
    #5
  6. Christopher Benson-Manica wrote:
    > Jack Klein <> spoke thus:
    >>> Christopher Benson-Manica wrote:
    >>> Are the members of a struct guaranteed to have ascending memory

    addresses?
    >>
    >>Yes, always in C.

    >
    > Just for my edification, what is the chapter and verse? Thanks...


    In C90, it's 6.5.2.1, verse 11:

    "Within a structure object, the non-bit-field members and the units in
    which bit-fields reside have addresses that increase in the order in
    which they are declared."

    This is a bit vague, since you don't technically declare the units
    bit-fields reside in (but rather the bit-fields that go in them, but
    adjacent bits fields do go into each unit). Bit-field members within a
    unit are in implementation-defined order.
    --
    Derrick Coetzee
    I grant this newsgroup posting into the public domain. I disclaim all
    express or implied warranty and all liability. I am not a professional.
     
    Derrick Coetzee, Sep 26, 2004
    #6
    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. JFCM
    Replies:
    4
    Views:
    5,767
  2. CoolPint
    Replies:
    8
    Views:
    1,018
    Jeff Schwab
    Dec 14, 2003
  3. Dave
    Replies:
    3
    Views:
    378
    tom_usenet
    Aug 10, 2004
  4. hdixon
    Replies:
    3
    Views:
    663
    hdixon
    Jul 9, 2006
  5. Replies:
    2
    Views:
    635
Loading...

Share This Page