struct data
{
char a;
int b;
}__attribute__((packed));
This is way to get the actual size of struct without any padding
http://tuxsudh.blogspot.com/2005/05/structure-packing-in-gcc.html

On Sun, Sep 4, 2011 at 2:38 AM, Debabrata Das <
debabrata.barunhal...@gmail.com> wrote:

> @Dheeraj, Thanks for the link
> @Anshul
> Considering double to be alligned as a 4 byte boundary..
> structc_tag
>
> c 1 byte
> padding 1 byte
> padding 1 byte
> padding 1 byte
> double 8 byte
> int    4 byte
>
> whole structure is multiple of 4 so no padding required.
>
> structd_tag
>
> 8 byte for double
> 4 byte for int
> 1 byte for char
>  padding 3 byte
>
> last 3 byte padding for structure size to be multiple of 4
>
> Correct me if am wrong....
>
> On Sun, Sep 4, 2011 at 2:40 AM, Anshul AGARWAL
> <anshul.agarwa...@gmail.com> wrote:
> > #include <stdio.h>
> >
> > // structure C
> > typedef struct structc_tag
> > {
> >    char        c;
> >    double      d;
> >    int         s;
> > } structc_t;
> >
> > // structure D
> > typedef struct structd_tag
> > {
> >    double      d;
> >    int         s;
> >    char        c;
> > } structd_t;
> >
> > int main()
> > {
> >
> >
> >    printf("sizeof(structc_t) = %d\n", sizeof(structc_t));
> >    printf("sizeof(structd_t) = %d\n", sizeof(structd_t));
> >
> >    return 0;
> > }
> > plz explain the output ??
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@googlegroups.com.
> > To unsubscribe from this group, send email to
> > algogeeks+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/algogeeks?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 

**Please do not print this e-mail until urgent requirement. Go Green!!
Save Papers <=> Save Trees
*BharatKumar Bagana*
**http://www.google.com/profiles/bagana.bharatkumar<http://www.google.com/profiles/bagana.bharatkumar>
*
Mobile +91 8056127652*
<bagana.bharatku...@gmail.com>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to