About structure member order

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • xcppcoder@gmail.com

    #1

    About structure member order

    Hello
    I want to send the data of a structure over TCP/IP, my question is that
    can I use this approach?

    struct
    {
    int val;
    char szVal[128];
    } mystruct;

    sendMyStruct(&m ystruct);

    receiveMyStruct (&myRecvStruct) ;

    The real question as I think, is there any difference between the
    previous structure and the following structure;

    struct
    {
    char szVal[128];
    int val;
    } mystruct;

    Thanks

  • Jakob Bieling

    #2
    Re: About structure member order

    xcppcoder@gmail .com wrote:
    [color=blue]
    > struct
    > {
    > int val;
    > char szVal[128];
    > } mystruct;[/color]

    The address of 'val' will always be lower than the address of
    'szVal'.
    [color=blue]
    > The real question as I think, is there any difference between the
    > previous structure and the following structure;
    >
    > struct
    > {
    > char szVal[128];
    > int val;
    > } mystruct;[/color]

    The address of 'val' will always be greater than the address of
    'szVal'.

    So: Yes. Be aware of padding issues between different
    compilers/platforms tho. Some compilers offer (obviously
    compiler-dependant) switches that allow you to specify the way a
    structure is padded.

    hth

    --
    jb

    (reply address in rot13, unscramble first)


    Comment

    • xcppcoder@gmail.com

      #3
      Re: About structure member order

      Thanks for your help

      Comment

      Working...