If you are using a GNU C compiler you can try to avoid it using

__attribute__((__packed__))

struct test
{
         unsigned char  field1;
         unsigned short field2;
         unsigned long  field3;
} __attribute__((__packed__));

sizeof(test) should work fine!

or in no GNU compiler you can try

#pragma pack


Regards,
Bruno Herrera



On 27 Mar 2007 07:21:13 -0700, Ravi Mishra <[EMAIL PROTECTED]> wrote:
>
>   Hi,
>
> In this case structure padding will occur due to bit alignment..
> To avoid this clause...take a instance of that structure as a pointer type
> and
> store every field. then dereference it according to data type what we have
> defiend in the structure field.
>
> Because we know the size of pinter id 4 byte...
> Note : this is gud , if we take int in the structure as a char array of 4
> byte.
> -Ravi
>
> On 27 Mar 2007 06:58:19 -0700, Thomas Hruska <[EMAIL 
> PROTECTED]<thruska%40cubiclesoft.com>
> >
> wrote:
> >
> > rshankar_gupta wrote:
> > > hi,can any one explain about structure paddig
> > >
> > > and what will be the size of this program with structure padding
> > >
> > > stucture foo
> > > {
> > > char c;
> > > int a;
> > > float b;
> > > };
> > >
> > > whether it will vary with 16/32 bit compilers
> >
> > sizeof(foo);
> >
> > If it matters what size it is, you can use #pragma options. Most
> > compilers offer #pragma directives to alter structure alignment rules.
> > Most of the time, the size of the structure shouldn't matter.
> >
> > --
> > Thomas Hruska
> > CubicleSoft President
> > Ph: 517-803-4197
> >
> > *NEW* VerifyMyPC 2.3
> > Change tracking and management tool.
> > Reduce tech. support times from 2 hours to 5 minutes.
> >
> > Free for personal use, $10 otherwise.
> > http://www.CubicleSoft.com/VerifyMyPC/<
> http://www.cubiclesoft.com/VerifyMyPC/>
> >
> >
> >
>
> [Non-text portions of this message have been removed]
>
>  
>



-- 
Bruno Meirelles Herrera
Eng. de Computação / Computer Eng.

SCJP -Sun Certified Programmer for Java 2 Platform 1.4
SCJA -  Sun Certified Associate for Java Platform


[Non-text portions of this message have been removed]

Reply via email to