Re: [algogeeks] Padding....

2011-09-04 Thread aditya kumar
padding related questions have been discussed many times . plz search.

On Sun, Sep 4, 2011 at 4:13 PM, bharatkumar bagana <
bagana.bharatku...@gmail.com> wrote:

> 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
>> int4 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
>>  wrote:
>> > #include 
>> >
>> > // structure C
>> > typedef struct structc_tag
>> > {
>> >charc;
>> >double  d;
>> >int s;
>> > } structc_t;
>> >
>> > // structure D
>> > typedef struct structd_tag
>> > {
>> >double  d;
>> >int s;
>> >charc;
>> > } 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
> *
> Mobile +91 8056127652*
> 
>
>
>  --
> 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.



Re: [algogeeks] Padding....

2011-09-04 Thread bharatkumar bagana
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
> int4 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
>  wrote:
> > #include 
> >
> > // structure C
> > typedef struct structc_tag
> > {
> >charc;
> >double  d;
> >int s;
> > } structc_t;
> >
> > // structure D
> > typedef struct structd_tag
> > {
> >double  d;
> >int s;
> >charc;
> > } 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
*
Mobile +91 8056127652*


-- 
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.



Re: [algogeeks] Padding....

2011-09-03 Thread Debabrata Das
@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
int4 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
 wrote:
> #include 
>
> // 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.



Re: [algogeeks] Padding....

2011-09-03 Thread Anshul AGARWAL
#include 

// structure C
typedef struct structc_tag
{
   charc;
   double  d;
   int s;
} structc_t;

// structure D
typedef struct structd_tag
{
   double  d;
   int s;
   charc;
} 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.



Re: [algogeeks] Padding....

2011-09-03 Thread Dheeraj Sharma
i thnk it should be
4 for int
1 for char
4 for float
3 padding to make multiple of 4..i read it from

http://forums.techarena.in/software-development/1241260.htm

correct me if am wrong

On Sun, Sep 4, 2011 at 1:54 AM, Karthikeyan palani  wrote:

> in 32 bit m/c
>
> 4 for int
> 1 for char + 3 padding
> 4 for float
>  so, totally it takes 12 bytes..
>
> On 03/09/2011, rahul sharma  wrote:
> > ans is: 16 i thninkj...
> > float take 8 bytes
> >
> > so pdding is :-
> >
> > int take 4 bytes
> > 1 char
> > 3 bytes pad
> > + 8 byte float=16
> >
> >
> > On Sat, Sep 3, 2011 at 10:30 PM, siddharam suresh
> > wrote:
> >
> >> each object in the structure will take one memory word.(if one object
> then
> >> its size of that object)
> >> Thank you,
> >> Sid.
> >>
> >>
> >>
> >> On Sat, Sep 3, 2011 at 10:27 PM, Debabrata Das <
> >> debabrata.barunhal...@gmail.com> wrote:
> >>
> >>> how  output is 12 on typical 32 bit system and why?
> >>> #include
> >>> struct x
> >>> {
> >>> int y;
> >>> char x;
> >>> float z;
> >>> };
> >>> main()
> >>> {
> >>> printf("%d",sizeof(struct x));
> >>> }
> >>>
> >>> what is the rule of padding
> >>>
> >>> --
> >>> 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.
> >>
> >
> > --
> > 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.
> >
> >
>
>
> --
> karthikeyankkn
>
> --
> 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.
>
>


-- 
*Dheeraj Sharma*
Comp Engg.
NIT Kurukshetra
+91 8950264227

-- 
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.



Re: [algogeeks] Padding....

2011-09-03 Thread Karthikeyan palani
in 32 bit m/c

4 for int
1 for char + 3 padding
4 for float
 so, totally it takes 12 bytes..

On 03/09/2011, rahul sharma  wrote:
> ans is: 16 i thninkj...
> float take 8 bytes
>
> so pdding is :-
>
> int take 4 bytes
> 1 char
> 3 bytes pad
> + 8 byte float=16
>
>
> On Sat, Sep 3, 2011 at 10:30 PM, siddharam suresh
> wrote:
>
>> each object in the structure will take one memory word.(if one object then
>> its size of that object)
>> Thank you,
>> Sid.
>>
>>
>>
>> On Sat, Sep 3, 2011 at 10:27 PM, Debabrata Das <
>> debabrata.barunhal...@gmail.com> wrote:
>>
>>> how  output is 12 on typical 32 bit system and why?
>>> #include
>>> struct x
>>> {
>>> int y;
>>> char x;
>>> float z;
>>> };
>>> main()
>>> {
>>> printf("%d",sizeof(struct x));
>>> }
>>>
>>> what is the rule of padding
>>>
>>> --
>>> 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.
>>
>
> --
> 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.
>
>


-- 
karthikeyankkn

-- 
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.



Re: [algogeeks] Padding....

2011-09-03 Thread rahul sharma
ans is: 16 i thninkj...
float take 8 bytes

so pdding is :-

int take 4 bytes
1 char
3 bytes pad
+ 8 byte float=16


On Sat, Sep 3, 2011 at 10:30 PM, siddharam suresh
wrote:

> each object in the structure will take one memory word.(if one object then
> its size of that object)
> Thank you,
> Sid.
>
>
>
> On Sat, Sep 3, 2011 at 10:27 PM, Debabrata Das <
> debabrata.barunhal...@gmail.com> wrote:
>
>> how  output is 12 on typical 32 bit system and why?
>> #include
>> struct x
>> {
>> int y;
>> char x;
>> float z;
>> };
>> main()
>> {
>> printf("%d",sizeof(struct x));
>> }
>>
>> what is the rule of padding
>>
>> --
>> 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.
>

-- 
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.



Re: [algogeeks] Padding....

2011-09-03 Thread siddharam suresh
each object in the structure will take one memory word.(if one object then
its size of that object)
Thank you,
Sid.



On Sat, Sep 3, 2011 at 10:27 PM, Debabrata Das <
debabrata.barunhal...@gmail.com> wrote:

> how  output is 12 on typical 32 bit system and why?
> #include
> struct x
> {
> int y;
> char x;
> float z;
> };
> main()
> {
> printf("%d",sizeof(struct x));
> }
>
> what is the rule of padding
>
> --
> 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.



[algogeeks] Padding....

2011-09-03 Thread Debabrata Das
how  output is 12 on typical 32 bit system and why?
#include
struct x
{
int y;
char x;
float z;
};
main()
{
printf("%d",sizeof(struct x));
}

what is the rule of padding

-- 
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.