linux-mips
[Top] [All Lists]

Re: Problem with sizeof?

To: Geert Uytterhoeven <geert@linux-m68k.org>
Subject: Re: Problem with sizeof?
From: Muthukumar Ratty <muthu5@sbcglobal.net>
Date: Mon, 8 Jul 2002 01:36:54 -0700 (PDT)
Cc: Muthukumar Ratty <muthu5@sbcglobal.net>, Venkatesh M R <venkatesh@multitech.co.in>, Linux/MIPS Development <linux-mips@oss.sgi.com>
In-reply-to: <Pine.GSO.4.21.0207081030130.3341-100000@vervain.sonytel.be>
Sender: owner-linux-mips@oss.sgi.com
Hi Geert,
The main reason I thought my environment could be broken is because I
got the problem with iproute2 by Alexey!! Anyway I sent a mail to
Alexey to check with him.
Thanks,
Muthu

On Mon, 8 Jul 2002, Geert Uytterhoeven wrote:

> On Mon, 8 Jul 2002, Muthukumar Ratty wrote:
> > > I am  not sure, but can this be memory allignment problem ?
> > > you can check this by adding one more (dummy ) element of __u32 length 
> > > (MIPS
> > > should print 40 insted of 44 and pc shuld print 40 as expected )
> >
> > You are right. when I add a __u32 dummy  to the tc_stats then it still
> > prints the size as 40. Is it get padded at the end? My main concern is,
> > is this a normal behavior or do I need to upgrade my MIPS build
> > environment?
>
> The alignment rule for 64-bit value is 8 bytes on MIPS, and only 4 bytes on
> ia32.
>
> Since sizeof(struct ...) must return a value that's a multiple of the 
> alignment
> rule for the largest element in the struct, it returns 40 on MIPS.
>
> > Thanks a lot,
> > Muthu.
> >
> > >
> > > if  it works then you can get rid of the above problem by changing the
> > > compilar settings.
> > >
> > > Regards,
> > > venkatesh M R
> > >
> > >
> > >
> > >
> > > Muthukumar Ratty wrote:
> > >
> > > > Hi,
> > > > In my MIPS system sizeof(struct tc_stats) returns 40 but it returns 36 
> > > > in
> > > > i386 PC.
> > > >
> > > > tc_stats is defined in include/linux/pkt_sched.c as
> > > > struct tc_stats
> > > > {
> > > >         __u64   bytes;                  /* NUmber of enqueues bytes */
> > > >         __u32   packets;                /* Number of enqueued packets   
> > > > */
> > > >         __u32   drops;                  /* Packets dropped because of 
> > > > lack
> > > > of resources */
> > > >         __u32   overlimits;             /* Number of throttle events 
> > > > when
> > > > this
> > > >                                          * flow goes out of allocated
> > > > bandwidth*/
> > > >         __u32   bps;                    /* Current flow byte rate */
> > > >         __u32   pps;                    /* Current flow packet rate */
> > > >         __u32   qlen;
> > > >         __u32   backlog;
> > > > #ifdef __KERNEL__
> > > >         spinlock_t *lock;
> > > > #endif
> > > > };
> > > > I printed the offsets of individual fields and they are same in i386 and
> > > > MIPS. If the "spinlock_t" is defined then this may be the case but I
> > > > am compiling an application, so it shouldnt be there? Right now I
> > > > think the problem could be with the "sizeof" operator.
> > > > Could someone please let me know if this is the case or I am doing
> > > > something wrong. Also any solution.
>
> Gr{oetje,eeting}s,
>
>                                               Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
>                                                           -- Linus Torvalds
>



<Prev in Thread] Current Thread [Next in Thread>