Re: need to initialize a member of a struct (error doing it)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2004-08-26 at 21:36 +0000, Cristina Rivera wrote:

Hi, Cristina.  Your cousin Chris seems to be greatly enjoying SC!

> struct bitmap_struct bitmapped;
> bitmapped.bitmaptask->pid= -1;  -----> the compiling error is appearing here
> EXPORT_SYMBOL(bitmapped);

You cannot define variables like that.  Ever, in C.

E.g. what you are doing is basically inserting random C statements into
nowhere.  There is no valid scope.

You have to initialize the variables at definition time, e.g.:

	struct foo {
		int x;
		char b;
	};

	struct foo my_struct = { 7, 'r' };

But then you have another problem.

In your code, bitmaptask is a POINTER not an actual structure.  So it is
initialized to NULL per ANSI C.  Or it is initialized to whatever value
you init it to.  Either way, unless it points to a valid task, you
cannot dereference it to get pid.  Moreover, even if it did point to a
valid task, unless you pin the task, it can race and exit anyhow.

Basically there is no way to do what you are trying to do.

I suggest using an init function along with locks and other normal
kernel coding practices.

	Robert Love
	


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux