c - invalid type argument of '->' -


#include <linux/kernel.h> #include <linux/sched.h> #include <linux/module.h>  int start(void){      printk("starting module\n");     printk("pid\ttask_name\tstate\n");      struct task_struct *task;     struct list_head *list;      list_for_each(list,&init_task->children){         task=list_entry(list,struct task_struct,sibling);         printk("%5d\t%s\t%li\n",task->pid,task->comm,task->state);     }     return 0; }   void ending(void){     printk("closing module\n"); }  module_init(start); module_exit(ending); 

when compile, error below shows up

error: invalid type argument of ‘->’ (have ‘struct task_struct’)   list_for_each(list,&init_task->children){                                ^ include/linux/list.h:408:14: note: in definition of macro ‘list_for_each’   (pos = (head)->next; pos != (head); pos = pos->next) 

i think error msg trying "&init_task" should have "struct task_struct" doesn't suffice? far know, variable 'init_task' externally declared in 'linux/sched.h' means error shouldn't caused not being able locate or find 'init_task'.

since pointer should come in front of '->', using '&init_task' seems right.

could point out i'm missing here?

---update: solved ---

reconsidering operator precedences of '->' , '&', proper use either '(&init_task)->children' or 'init_task.children'. however, changed, error came up:

include/linux/list.h:408:31: error: invalid operands binary != (have ‘struct list_head *’ , ‘struct list_head’)   (pos = (head)->next; pos != (head); pos = pos->next) 

this error msg pointed out should providing address of 'children' in 'struct task_struct'. thus, changed problematic line as:

list_for_each(list,&(init_task.children)){ 

which solved problem , compilation went smoothly.

init_task structure, not pointer. should either convert pointer prior dereferencing (&init_task)->children, or access children using period notation init_task.children. &init_task->children denoting address of children field of structure pointed init_task, if pointer.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -