why some members in the struct lost after struct type compulsiontransformation - VxWorks

This is a discussion on why some members in the struct lost after struct type compulsiontransformation - VxWorks ; Hi, I an very confused about the following type compulsion transformation.The code is : typedef struct LEAF_S { unsigned short node_type; unsigned char tag; unsigned char type; void *testproc; }LEAF_T; typedef struct ARC_S { unsigned long id; struct ARC_S *nodep; ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: why some members in the struct lost after struct type compulsiontransformation

  1. why some members in the struct lost after struct type compulsiontransformation

    Hi, I an very confused about the following type compulsion
    transformation.The code is :
    typedef struct LEAF_S
    {
    unsigned short node_type;
    unsigned char tag;
    unsigned char type;
    void *testproc;
    }LEAF_T;

    typedef struct ARC_S
    {
    unsigned long id;
    struct ARC_S *nodep;
    } ARC_T;

    typedef struct NODE_S
    {
    unsigned short node_type;
    struct ARC_S *arcs; //
    } NODE_T;

    MIBNODE_T *np;
    MIBARC_T *ap;
    MIBLEAF_T lnode ={1,0x04,0x01,(void *)0x00402b70};
    np = (MIBNODE_T *)&lnode;

    after run the code, I found the pointer variable np had pointed the
    following value {1, 0x00402b70}, and the tag and type member of the
    Inode had lost in the np. Why it occur this. I thought np would
    pointed the following value
    {1, 0x2b700104}, and value "04 01" has existed there.
    Anyone can help me about the type transformation, especially the
    struct include the pointer.
    Any suggestions about the problem would be appriciated!

  2. Re: why some members in the struct lost after struct type compulsiontransformation

    On 77, 1024, lje9292...@yahoo.com.cn wrote:
    > Hi, I an very confused about the following type compulsion
    > transformation.The code is :
    > typedef struct LEAF_S
    > {
    > unsigned short node_type;
    > unsigned char tag;
    > unsigned char type;
    > void *testproc;
    > }LEAF_T;
    >
    > typedef struct ARC_S
    > {
    > unsigned long id;
    > struct ARC_S *nodep;
    >
    > } ARC_T;
    >
    > typedef struct NODE_S
    > {
    > unsigned short node_type;
    > struct ARC_S *arcs; //
    >
    > } NODE_T;
    >
    > MIBNODE_T *np;
    > MIBARC_T *ap;
    > MIBLEAF_T lnode ={1,0x04,0x01,(void *)0x00402b70};
    > np = (MIBNODE_T *)&lnode;
    >
    > after run the code, I found the pointer variable np had pointed the
    > following value {1 0x00402b70}, and the tag and type member of the
    > Inode had lost in the np. Why it occur this. I thought np would
    > pointed the following value
    > {1, 0x2b700104}, and value "04 01" has existed there.
    > Anyone can help me about the type transformation, especially the
    > struct include the pointer.
    > Any suggestions about the problem would be appriciated!


    Sorry, the code has some error, It should as follows:
    typedef struct LEAF_S
    {
    unsigned short node_type;
    unsigned char tag;
    unsigned char type;
    void *testproc;
    }LEAF_T;

    typedef struct ARC_S
    {
    unsigned long id;
    struct ARC_S *nodep;

    } ARC_T;

    typedef struct NODE_S
    {
    unsigned short node_type;
    struct ARC_S *arcs; //

    } NODE_T;

    NODE_T *np;
    ARC_T *ap;
    LEAF_T lnode ={1,0x04,0x01,(void *)0x00402b70};
    np = (NODE_T *)&lnode;

  3. Re: why some members in the struct lost after struct type compulsiontransformation

    In fact, member in structures will be aligned according to your
    complier configuration.
    Use #pragma pack(?) to specify packing alignment for structure
    explicitly.
    In your case, #pragma pack(1) should be used.


  4. Re: why some members in the struct lost after struct type compulsiontransformation

    On 712, 1153, ganyong wrote:
    > In fact, member in structures will be aligned according to your
    > complier configuration.
    > Use #pragma pack(?) to specify packing alignment for structure
    > explicitly.
    > In your case, #pragma pack(1) should be used.


    Yes, Thank your reply. But in my code it didn't use the #pragma
    pack(?), not the #pragma align 1.
    I don't know the difference between them. why the code use the
    following:

    #if ((CPU_FAMILY==I960) && (defined __GNUC__))
    #pragma align 1
    #endif

    Could you give me the answer?
    Thank you!


  5. Re: why some members in the struct lost after struct type compulsiontransformation

    On Jul 13, 6:02 pm, lje9292...@yahoo.com.cn wrote:
    > On 712, 1153, ganyong wrote:
    >
    > > In fact, member in structures will be aligned according to your
    > > complier configuration.
    > > Use #pragma pack(?) to specify packing alignment for structure
    > > explicitly.
    > > In your case, #pragma pack(1) should be used.

    >
    > Yes, Thank your reply. But in my code it didn't use the #pragma
    > pack(?), not the #pragma align 1.
    > I don't know the difference between them. why the code use the
    > following:
    >
    > #if ((CPU_FAMILY==I960) && (defined __GNUC__))
    > #pragma align 1
    > #endif
    >
    > Could you give me the answer?
    > Thank you!


    The code snippet means that if your processor is I960 family and you
    are compiling the c code using GNU C style coding the the data will be
    byte alignment.

    In the code snippet mentioned by you, the alignment is playing a major
    role hence you are seeing the correct results..probably your code is
    4bytes aligned. Can you tell me what processor you are using ?

    Probably you can check the alignment by printing the size of the three
    structures and then comparing.

    All the best,
    Manish Gupta

  6. Re: why some members in the struct lost after struct type compulsiontransformation

    On 715, 832, Manish wrote:
    > On Jul 13, 6:02 pm, lje9292...@yahoo.com.cn wrote:
    >
    >
    >
    > > On 712, 1153, ganyong wrote:

    >
    > > > In fact, member in structures will be aligned according to your
    > > > complier configuration.
    > > > Use #pragma pack(?) to specify packing alignment for structure
    > > > explicitly.
    > > > In your case, #pragma pack(1) should be used.

    >
    > > Yes, Thank your reply. But in my code it didn't use the #pragma
    > > pack(?), not the #pragma align 1.
    > > I don't know the difference between them. why the code use the
    > > following:

    >
    > > #if ((CPU_FAMILY==I960) && (defined __GNUC__))
    > > #pragma align 1
    > > #endif

    >
    > > Could you give me the answer?
    > > Thank you!

    >
    > The code snippet means that if your processor is I960 family and you
    > are compiling the c code using GNU C style coding the the data will be
    > byte alignment.
    >
    > In the code snippet mentioned by you, the alignment is playing a major
    > role hence you are seeing the correct results..probably your code is
    > 4bytes aligned. Can you tell me what processor you are using ?
    >
    > Probably you can check the alignment by printing the size of the three
    > structures and then comparing.
    >
    > All the best,
    > Manish Gupta


    Thank you for your reply. I am using the pentium processor. And the
    result is
    NODE_T has 8 bytes!
    ARC_T has 8 bytes!
    LEAF_T has 8 bytes!
    Yes, if my compiler is 4bytes aligned. Maybe it is right!



  7. Re: why some members in the struct lost after struct type compulsiontransformation

    On Jul 16, 5:40 am, lje9292...@yahoo.com.cn wrote:
    > On 715, 832, Manish wrote:
    >
    >
    >
    >
    >
    > > On Jul 13, 6:02 pm, lje9292...@yahoo.com.cn wrote:

    >
    > > > On 712, 1153, ganyong wrote:

    >
    > > > > In fact, member in structures will be aligned according to your
    > > > > complier configuration.
    > > > > Use #pragma pack(?) to specify packing alignment for structure
    > > > > explicitly.
    > > > > In your case, #pragma pack(1) should be used.

    >
    > > > Yes, Thank your reply. But in my code it didn't use the #pragma
    > > > pack(?), not the #pragma align 1.
    > > > I don't know the difference between them. why the code use the
    > > > following:

    >
    > > > #if ((CPU_FAMILY==I960) && (defined __GNUC__))
    > > > #pragma align 1
    > > > #endif

    >
    > > > Could you give me the answer?
    > > > Thank you!

    >
    > > The code snippet means that if your processor is I960 family and you
    > > are compiling the c code using GNU C style coding the the data will be
    > > byte alignment.

    >
    > > In the code snippet mentioned by you, the alignment is playing a major
    > > role hence you are seeing the correct results..probably your code is
    > > 4bytes aligned. Can you tell me what processor you are using ?

    >
    > > Probably you can check the alignment by printing the size of the three
    > > structures and then comparing.

    >
    > > All the best,
    > > Manish Gupta

    >
    > Thank you for your reply. I am using the pentium processor. And the
    > result is
    > NODE_T has 8 bytes!
    > ARC_T has 8 bytes!
    > LEAF_T has 8 bytes!
    > Yes, if my compiler is 4bytes aligned. Maybe it is right!- Hide quoted text -
    >
    > - Show quoted text -


    Then you have the answer !! I think you understood how its
    working..if still not clear write back we will make it clear..

    Great!
    -Manish Gupta

  8. Re: why some members in the struct lost after struct type compulsiontransformation

    On 717, 414, Manish wrote:
    > On Jul 16, 5:40 am, lje9292...@yahoo.com.cn wrote:
    >
    >
    >
    > > On 715, 832, Manish wrote:

    >
    > > > On Jul 13, 6:02 pm, lje9292...@yahoo.com.cn wrote:

    >
    > > > > On 712, 1153, ganyong wrote:

    >
    > > > > > In fact, member in structures will be aligned according to your
    > > > > > complier configuration.
    > > > > > Use #pragma pack(?) to specify packing alignment for structure
    > > > > > explicitly.
    > > > > > In your case, #pragma pack(1) should be used.

    >
    > > > > Yes, Thank your reply. But in my code it didn't use the #pragma
    > > > > pack(?), not the #pragma align 1.
    > > > > I don't know the difference between them. why the code use the
    > > > > following:

    >
    > > > > #if ((CPU_FAMILY==I960) && (defined __GNUC__))
    > > > > #pragma align 1
    > > > > #endif

    >
    > > > > Could you give me the answer?
    > > > > Thank you!

    >
    > > > The code snippet means that if your processor is I960 family and you
    > > > are compiling the c code using GNU C style coding the the data will be
    > > > byte alignment.

    >
    > > > In the code snippet mentioned by you, the alignment is playing a major
    > > > role hence you are seeing the correct results..probably your code is
    > > > 4bytes aligned. Can you tell me what processor you are using ?

    >
    > > > Probably you can check the alignment by printing the size of the three
    > > > structures and then comparing.

    >
    > > > All the best,
    > > > Manish Gupta

    >
    > > Thank you for your reply. I am using the pentium processor. And the
    > > result is
    > > NODE_T has 8 bytes!
    > > ARC_T has 8 bytes!
    > > LEAF_T has 8 bytes!
    > > Yes, if my compiler is 4bytes aligned. Maybe it is right!- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Then you have the answer !! I think you understood how its
    > working..if still not clear write back we will make it clear..
    >
    > Great!
    > -Manish Gupta


    Thank you! You are so kind!

+ Reply to Thread