Re: Use a variable before it's declaration

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

 



Rock Lee <rocklee_104@xxxxxxxxxxx> writes:

>> Rock Lee <rocklee_104@xxxxxxxxxxx> writes:
>>
>>> Hi, all:
>>> 	Here is a snippet of linux-v3.4 which drives me crazy.
>>> Because init_task hasn't been declared yet when init_thread_union is
>>> initializing. Why is there no compiling error? Any hint would be helpful.
>>>
>>> union thread_union init_thread_union __init_task_data =
>>>
>>>       { INIT_THREAD_INFO(init_task) };
>>>
>>>
>>>
>>> /*
>>>
>>>    * Initial task structure.
>>>
>>>    *
>>>
>>>    * All other task structs will be allocated on slabs in fork.c
>>>
>>>    */
>>>
>>> struct task_struct init_task = INIT_TASK(init_task);
>>
>>
>> Because init_task is declared "extern" in linux/sched.h
>>
>>
>> Bjørn
>
> I do something like that:
>
> extern int b;
> int a = b + 10;
> int b = 20;
>
> int main(void)
> {
> 	return 0;
> }
>
> No doubt, compiling error.

Sure.  That's a completely different issue. But this works:

extern int b;
int *a = &b;
int b = 20;

int main(void)
{
 	return 0;
}

and that's what the code you refer do does.



Bjørn


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies




[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