Re: structure definition in a .c file rather than .h file

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

 



grep -r sched_fair.c sched.c;
see "kernel/sched.c",you will find that how sched_fair.c is used.

#include "sched_stats.h"
#include "sched_idletask.c"
#include "sched_fair.c"
#include "sched_rt.c"
#ifdef CONFIG_SCHED_DEBUG
# include "sched_debug.c"

That 's clearly.....
I don't think it is good programming manner. But it 's really in many
places of kernel. ^-^


2009/3/13 Sukanto Ghosh <sukanto.cse.iitb@xxxxxxxxx>:
> I understand forward declaration ... But have a look at
> kernel/sched_fair.c ... struct cfs_rq has been used a number of places
> in it, but they don't even have a forward declaration of the
> structure. The only header file that gets included is
> linux/latencytop.h ... which doesn't includes any header that has a
> forward declaration of struct cfs_rq.  so, how does the compiler gives
> no errors ?
>
> If I just assume that i am missing a place from where the structure
> gets the forward declaration (forward declaration is in linux\sched.h
> header) ...  how are the fields of this structure being accessed
> inside kernel/sched_fair.c ?
>
> Now, if I assume that somehow the compiler gets the complete
> declaration of "struct cfs_rq" inside kernel/sched_fair.c ... then why
> does the compiler complains when I try to write a kprobe module for
> the a function "__enqueue_entity" of kernel/sched_fair.c which
> accesses the fields of this structure.
>
> I can understand why the compiler is complaining but why doesn't it do
> so for the kernel/sched_fair.c case ...
>
> What am I missing ?
>
>
> On Thu, Mar 12, 2009 at 10:09 PM, Durga Prasad <writexdp@xxxxxxxxx> wrote:
>> Look for 'forward declaration' of variables in C.
>> You are telling the compiler that "I am declaring such a structure.
>> Understand it when you encounter it" .
>> - Durga
>>
>> ________________________________
>> From: Sukanto Ghosh <sukanto.cse.iitb@xxxxxxxxx>
>> To: Nelson Castillo <nelsoneci@xxxxxxxxx>; Pei Lin <telent997@xxxxxxxxx>
>> Cc: kernelnewbies <kernelnewbies@xxxxxxxxxxxx>
>> Sent: Thursday, March 12, 2009 3:06:46 PM
>> Subject: Re: structure definition in a .c file rather than .h file
>>
>> On Thu, Mar 12, 2009 at 11:58 AM, Nelson Castillo <nelsoneci@xxxxxxxxx>
>> wrote:
>>> On Thu, Mar 12, 2009 at 2:06 PM, Sukanto Ghosh
>>> <sukanto.cse.iitb@xxxxxxxxx> wrote:
>>>> Hi,
>>>>
>>>> The complete definition of structure cfs_rq is in a .c file
>>>> (kernel/sched.c). In the head linux/sched.h it has been declared as
>>>> "struct cfs_rq;"
>>>> What is the purpose of doing so ?
>>>
>>> With this declaration in linux/sched.h you can make pointers of the
>>> structure anywhere. All pointers have the same size thus it just
>>> doesn't matter if you don't know the details of the structure.
>>>
>>> The idea of not exposing the structure is just encapsulation. It means
>>> you shouldn't be touching those fields outside kernel/sched.c unless
>>> you use one of the provided API functions to do so (if any).
>>>
>>
>> exactly, and yet the fields have been used in kernel/sched_fair.c
>> .... this is what confuses me
>>
>>
>> --
>> Regards,
>> Sukanto Ghosh
>>
>> --
>> To unsubscribe from this list: send an email with
>> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
>> Please read the FAQ at http://kernelnewbies.org/FAQ
>>
>>
>>
>
>
>
> --
> Regards,
> Sukanto Ghosh
>

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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