[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: globals in modules
I am using 2.4.20 kernel on MIPS.
-Nilanjan
-----Original Message-----
From: Srinivas G. [mailto:srinivasg@xxxxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, May 03, 2006 11:31 AM
To: Nilanjan Roychowdhury; kernelnewbies
Subject: RE: globals in modules
> I am facing a problem
>
> In my source file I have something like this when I insert the module
I
> see all the values printed as 0xFFFF but when I remove one element
from
> the structure lets say c then I get correct result. Or when I add one
> element to the ctructure lets say d I get correct result. I mean when
> the size of the structre becomes 4,8,,16 I get right results. Whats
> wrong ??
>
>
> typedef struct {
> unsigned int a;
> unsigned int b;
> unsigned int c;
>
> }my_struct;
> my_struct my_array[4];
>
> int __init init_module(void)
> {
> int i =0;
> for ( i=0; i< 4; i++)
> {
> my_array [i].a = i;
> my_array [i].b = i + 10;
> my_array [i].c = i + 20;
> }
> for ( i=0; i< 4; i++)
> {
> printk(" a = 0x%x,b = 0x%x, c = 0x%x\n", my_array [i].a, my_array
> [i].b,my_array [i].c); }
> }
Dear Nil,
There is nothing wrong in the code. I have tested the above code on my
FC3 system. It is working fine.
Coming to the size restrictions, the compiler allocates the sizes for
the structures in the multiple of 4 always. If you have the structure
like
struct size_test
{
int a;
char b;
}abc;
If you print the size of the above structure variable (abc) it shows you
8.
Bye the bye, what version of kernel is you using?
Thanks and Regards,
Srinivas G
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/