GeeksforGeeks » C/C++ Programming Questions
A C structure padding question
(9 posts)-
how can we turn-off the padding in structures?
-
#pragma pack 1..... before structure declaration
-
sorry.....#pragma pack(1)..... before structure declaration ...i dont know wat exactly does it mean..can anyone explain?
-
use __attribute__((packed)) with GCC
-
can any1 tell this;;;;---
Why size of this structue is 16bytes instead of 20
struct aah
{
char i;
double j;
int k;
}; -
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. -
@ashmita:
size of structure is : 16 bytes (for 32 bit machines)
char(1) + padding(3) + 8 (double) + 4(char) -
I checked on Dev C++, Visual C++ 2010, & Code Blocks.... it is giving 24 bytes...
Reply
You must log in to post.