GeeksforGeeks » C/C++ Programming Questions

A C structure padding question

(9 posts)

Tags:

  1. gagan
    guest
    Posted 1 year ago #

    how can we turn-off the padding in structures?

  2. sunil gc
    guest
    Posted 1 year ago #

    #pragma pack 1..... before structure declaration

  3. sunil gc
    guest
    Posted 1 year ago #

    sorry.....#pragma pack(1)..... before structure declaration ...i dont know wat exactly does it mean..can anyone explain?

  4. Logic
    guest
    Posted 1 year ago #

  5. Himanshu
    guest
    Posted 1 year ago #

    use __attribute__((packed)) with GCC

  6. ashmita
    guest
    Posted 7 months ago #

    can any1 tell this;;;;---
    Why size of this structue is 16bytes instead of 20
    struct aah
    {
    char i;
    double j;
    int k;
    };

  7. devan
    guest
    Posted 7 months ago #

    ashmita,

    The size of the struct is compiler dependent I guess. Because i get it as 24. As far as I think 24 is the correct answer.
    char(1)+padding(7)+double(8)+int(4)+padding(4)=24.
    If you are wondering why there is a padding at the end, then it is for the struct itself.

  8. Narendra.
    guest
    Posted 7 months ago #

    @ashmita:

    size of structure is : 16 bytes (for 32 bit machines)
    char(1) + padding(3) + 8 (double) + 4(char)

  9. Kapil
    guest
    Posted 4 months ago #

    I checked on Dev C++, Visual C++ 2010, & Code Blocks.... it is giving 24 bytes...


Reply

You must log in to post.

RSS feed for this topic