Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Viewing the padded bytes

Reply
Thread Tools

Viewing the padded bytes

 
 
karthikbalaguru
Guest
Posts: n/a
 
      01-14-2009
Hi ,

I have the below structure.
struct check_struct{
double a;
char b;
};
My system reports the size of the above structure as 16 bytes.

I understand that there is some padding at the end of the above
structure and hence the size gets calculated to 16 bytes.
But, how to view the data/info that are padded using a debugger
like gdb or visual c++ debugger ?

I used watch windows but, it did not show the padded data .
Any ideas ?

Thx in advans,
Karthik Balaguru
 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      01-14-2009
On Jan 14, 12:41*am, karthikbalaguru <(E-Mail Removed)>
wrote:
> Hi ,
>
> I have the below structure.
> struct check_struct{
> * * * * double a;
> * * * * char b;};
>
> My system reports the size of the above structure as 16 bytes.
>
> I understand that there is some padding at the end of the above
> structure and hence the size gets calculated to 16 bytes.
> But, how to view the data/info that are padded using a debugger
> like gdb or visual c++ debugger ?
>
> I used watch windows but, it did not show the padded data .
> Any ideas ?


typedef struct check_struct {
double a;
char b;
} check_struct_type;

check_struct_type cs = {0};
unsigned char *csp = (unsigned char *) &cs;

Why do you care? You cannot depend on anything about the padding
bytes.
They might contain all zeros on one invocation and 0xDEADBEE on
another.
 
Reply With Quote
 
 
 
 
David Webber
Guest
Posts: n/a
 
      01-14-2009

"karthikbalaguru" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> I have the below structure.
> struct check_struct{
> double a;
> char b;
> };
> My system reports the size of the above structure as 16 bytes.
>
> I understand that there is some padding at the end of the above
> structure and hence the size gets calculated to 16 bytes.
> But, how to view the data/info that are padded using a debugger
> like gdb or visual c++ debugger ?
>
> I used watch windows but, it did not show the padded data .
> Any ideas ?


I don't like having structures a different size from what I see on the page.
It makes me nervous. So I would always write the above as

struct check_struct
{
double a;
char b;
char reserved[7];
};

If you do that you can see the padded bytes.

Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm

 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      01-14-2009
"David Webber" <(E-Mail Removed)> writes:

> "karthikbalaguru" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> I have the below structure.
>> struct check_struct{
>> double a;
>> char b;
>> };
>> My system reports the size of the above structure as 16 bytes.
>>
>> I understand that there is some padding at the end of the above
>> structure and hence the size gets calculated to 16 bytes.
>> But, how to view the data/info that are padded using a debugger
>> like gdb or visual c++ debugger ?
>>
>> I used watch windows but, it did not show the padded data .
>> Any ideas ?

>
> I don't like having structures a different size from what I see on the
> page. It makes me nervous. So I would always write the above as
>
> struct check_struct
> {
> double a;
> char b;
> char reserved[7];
> };
>
> If you do that you can see the padded bytes.
>
> Dave


Assuming things it shouldn't - I dont like that at all.

Those bytes are not reserved either - they are padding. Two totally
different things I think.

To the OP. Use the debugger and examine the memory at the address of the
struct. e.g in gdb to see 8 hex words

(gdb)x/8x &myStruct



--
I'm not a person who particularly had heros when growing up.
- What Dennis Ritchie could potentially say when asked about the hero worship coming from c.l.c.
 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      01-14-2009
On 14 Jan, 13:37, Richard <(E-Mail Removed)> wrote:

<snip>

> --
> I'm not a person who particularly had heros when growing up.
> *- *What Dennis Ritchie could potentially say when asked about the hero worship coming from c.l.c


I thought you were going to fix your misleading sig?

 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      01-14-2009
On 14 Jan, 13:37, Richard <(E-Mail Removed)> wrote:
> "David Webber" <(E-Mail Removed)> writes:
> > "karthikbalaguru" <(E-Mail Removed)> wrote in message
> >news:(E-Mail Removed)...

>
> >> I have the below structure.
> >> struct check_struct{
> >> double a;
> >> char b;
> >> };
> >> My system reports the size of the above structure as 16 bytes.

>
> >> I understand that there is some padding at the end of the above
> >> structure and hence the size gets calculated to 16 bytes.
> >> But, how to view the data/info that are padded using a debugger
> >> like gdb or visual c++ debugger ?

>
> >> I used watch windows but, it did not show the padded data .
> >> Any ideas ?

>
> > I don't like having structures a different size from what I see on the
> > page. It makes me nervous. * So I would always write the above as

>
> > struct check_struct
> > {
> > * *double a;
> > * *char b;
> > * *char reserved[7];
> > };

>
> > If you do that you can see the padded bytes.

>
> > Dave

>
> Assuming things it shouldn't - I dont like that at all.
>
> Those bytes are not reserved either - they are padding. Two totally
> different things I think.
>
> To the OP. Use the debugger and examine the memory at the address of the
> struct. e.g in gdb to see 8 hex words
>
> (gdb)x/8x &myStruct
>
> --
> I'm not a person who particularly had heros when growing up.
> *- *What Dennis Ritchie could potentially say when asked about the hero worship coming from c.l.c


oh sugar. ok *now* I've read what it actually says. sorry

 
Reply With Quote
 
nick_keighley_nospam@hotmail.com
Guest
Posts: n/a
 
      01-14-2009
On 14 Jan, 13:00, "David Webber" <(E-Mail Removed)>
wrote:
> "karthikbalaguru" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...


> > I have the below structure.
> > struct check_struct{
> > double a;
> > char b;
> > };
> >
> > My system reports the size of the above structure as 16 bytes.

>
> > I understand that there is some padding at the end of the above
> > structure and hence the size gets calculated to 16 bytes.
> > But, how to view the data/info that are padded using a debugger
> > like gdb or visual c++ debugger ?


why do you need to see the padding bytes?

> > I used watch windows but, it did not show the padded data .
> > Any ideas ?

>
> I don't like having structures a different size from what I see on the page.
> It makes me nervous. *


stop programming in C then.


> So I would always write the above as
>
> struct check_struct
> {
> * * double a;
> * * char b;
> * * char reserved[7];
>
> };
>
> If you do that you can see the padded bytes.


what happens when they change?

 
Reply With Quote
 
swengineer001@gmail.com
Guest
Posts: n/a
 
      01-14-2009
On Jan 14, 8:00*am, "David Webber" <(E-Mail Removed)>
wrote:
> "karthikbalaguru" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > I have the below structure.
> > struct check_struct{
> > double a;
> > char b;
> > };
> > My system reports the size of the above structure as 16 bytes.

>
> > I understand that there is some padding at the end of the above
> > structure and hence the size gets calculated to 16 bytes.
> > But, how to view the data/info that are padded using a debugger
> > like gdb or visual c++ debugger ?

>
> > I used watch windows but, it did not show the padded data .
> > Any ideas ?

>
> I don't like having structures a different size from what I see on the page.
> It makes me nervous. * So I would always write the above as
>
> struct check_struct
> {
> * * double a;
> * * char b;
> * * char reserved[7];
>
> };
>
> If you do that you can see the padded bytes.


I don't think so. It will always show you the reserved member's
contents but I think the implementation is still free to insert
padding in any amount and at any location in this structure it
pleases, except at the beggining.

>
> Dave
> --
> David Webber
> Author of 'Mozart the Music Processor'http://www.mozart.co.uk
> For discussion/support seehttp://www.mozart.co.uk/mozartists/mailinglist.htm


 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      01-14-2009
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> On 14 Jan, 13:37, Richard <(E-Mail Removed)> wrote:
>
> <snip>
>
>> --
>> I'm not a person who particularly had heros when growing up.
>> *- *What Dennis Ritchie could potentially say when asked about the hero worship coming from c.l.c

>
> I thought you were going to fix your misleading sig?
>


I thought you were going to stop being an idiot and read it. Or are you
going to do a Heathfield and start demanding apologies for other people?

--
I'm not a person who particularly had heros when growing up.
- What Dennis Ritchie could potentially say when asked about the hero worship coming from c.l.c.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      01-14-2009
(E-Mail Removed) writes:

> On 14 Jan, 13:37, Richard <(E-Mail Removed)> wrote:
>> "David Webber" <(E-Mail Removed)> writes:
>> > "karthikbalaguru" <(E-Mail Removed)> wrote in message
>> >news:(E-Mail Removed)...

>>
>> >> I have the below structure.
>> >> struct check_struct{
>> >> double a;
>> >> char b;
>> >> };
>> >> My system reports the size of the above structure as 16 bytes.

>>
>> >> I understand that there is some padding at the end of the above
>> >> structure and hence the size gets calculated to 16 bytes.
>> >> But, how to view the data/info that are padded using a debugger
>> >> like gdb or visual c++ debugger ?

>>
>> >> I used watch windows but, it did not show the padded data .
>> >> Any ideas ?

>>
>> > I don't like having structures a different size from what I see on the
>> > page. It makes me nervous. * So I would always write the above as

>>
>> > struct check_struct
>> > {
>> > * *double a;
>> > * *char b;
>> > * *char reserved[7];
>> > };

>>
>> > If you do that you can see the padded bytes.

>>
>> > Dave

>>
>> Assuming things it shouldn't - I dont like that at all.
>>
>> Those bytes are not reserved either - they are padding. Two totally
>> different things I think.
>>
>> To the OP. Use the debugger and examine the memory at the address of the
>> struct. e.g in gdb to see 8 hex words
>>
>> (gdb)x/8x &myStruct
>>
>> --
>> I'm not a person who particularly had heros when growing up.
>> *- *What Dennis Ritchie could potentially say when asked about the hero worship coming from c.l.c

>
> oh sugar. ok *now* I've read what it actually says. sorry
>


heh :-; No harm. But I did reply before I saw your acknowledgement.


--
I'm not a person who particularly had heros when growing up.
- What Dennis Ritchie could potentially say when asked about the hero worship coming from c.l.c.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BufferedOutputStream being padded with spaces? hystable@yahoo.com Java 4 08-03-2005 07:27 PM
Carriage return/line feed padded to last value in a NameValueCollection John Dalberg ASP .Net 0 01-21-2005 10:17 PM
regex matching fixed-width padded fields Roy Smith Java 2 05-03-2004 03:08 AM
javax.crypto.BadPaddingException: Given final block not properly padded yishushui@hotmail.com Java 0 03-06-2004 03:30 AM
Bitfield structs that are not padded to the size of an int? Davide Bruzzone C Programming 9 08-27-2003 09:04 AM



Advertisments