* [RFC]confusions about 'struct' define
@ 2012-05-30 16:50 harryxiyou
2012-05-30 17:20 ` Gaurav Jain
2012-05-31 16:40 ` michi1 at michaelblizek.twilightparadox.com
0 siblings, 2 replies; 7+ messages in thread
From: harryxiyou @ 2012-05-30 16:50 UTC (permalink / raw)
To: kernelnewbies
Hi guys,
When I read the linux/device.h file for some device driver usage, i find some
confusions like following.
$ head -60 device.h
[...]
struct device;
struct device_private;
struct device_driver;
struct driver_private;
struct module;
struct class;
struct subsys_private;
struct bus_type;
struct device_node;
struct iommu_ops;
struct bus_attribute {
struct attribute attr;
ssize_t (*show)(struct bus_type *bus, char *buf);
ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
};
[...]
I have never seen struct define like
"struct device;
struct device_private;
struct device_driver;
[...]
struct device_node;
struct iommu_ops;"
The common define is like this
"struct a{
int a;
int b;
[...]
}"
Is this just struct declaration or some extension about gcc? Cloud
anyone give me
some explanations?
Thanks in advance ;-)
Note: my kernel version is 3.0 around.
--
Thanks
Harry Wei
^ permalink raw reply [flat|nested] 7+ messages in thread* [RFC]confusions about 'struct' define
2012-05-30 16:50 [RFC]confusions about 'struct' define harryxiyou
@ 2012-05-30 17:20 ` Gaurav Jain
2012-05-30 17:37 ` harryxiyou
2012-05-31 16:40 ` michi1 at michaelblizek.twilightparadox.com
1 sibling, 1 reply; 7+ messages in thread
From: Gaurav Jain @ 2012-05-30 17:20 UTC (permalink / raw)
To: kernelnewbies
Those are forward declarations as they are being used in defining struct
bus_attribute. It's nothing special about GNU-C. That's the case for ANSI-C
too. Pretty standard.
On Wed, May 30, 2012 at 10:20 PM, harryxiyou <harryxiyou@gmail.com> wrote:
> Hi guys,
>
> When I read the linux/device.h file for some device driver usage, i find
> some
> confusions like following.
>
> $ head -60 device.h
> [...]
>
> struct device;
> struct device_private;
> struct device_driver;
> struct driver_private;
> struct module;
> struct class;
> struct subsys_private;
> struct bus_type;
> struct device_node;
> struct iommu_ops;
>
> struct bus_attribute {
> struct attribute attr;
> ssize_t (*show)(struct bus_type *bus, char *buf);
> ssize_t (*store)(struct bus_type *bus, const char *buf, size_t
> count);
> };
> [...]
>
> I have never seen struct define like
>
> "struct device;
> struct device_private;
> struct device_driver;
> [...]
> struct device_node;
> struct iommu_ops;"
>
> The common define is like this
>
> "struct a{
> int a;
> int b;
> [...]
> }"
>
> Is this just struct declaration or some extension about gcc? Cloud
> anyone give me
> some explanations?
> Thanks in advance ;-)
>
> Note: my kernel version is 3.0 around.
>
> --
> Thanks
> Harry Wei
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
--
Gaurav Jain
Associate Software Engineer
VxVM Escalations Team, SAMG
Symantec Software India Pvt. Ltd.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120530/144cb394/attachment.html
^ permalink raw reply [flat|nested] 7+ messages in thread* [RFC]confusions about 'struct' define
2012-05-30 17:20 ` Gaurav Jain
@ 2012-05-30 17:37 ` harryxiyou
2012-06-01 9:30 ` Bernd Petrovitsch
0 siblings, 1 reply; 7+ messages in thread
From: harryxiyou @ 2012-05-30 17:37 UTC (permalink / raw)
To: kernelnewbies
On Thu, May 31, 2012 at 1:20 AM, Gaurav Jain <gjainroorkee@gmail.com> wrote:
Hi Gaurav,
> Those are forward declarations as they are being used in defining struct
> bus_attribute. It's nothing special about GNU-C. That's the case for ANSI-C
> too. Pretty standard.
>
Hmmm.., that is to say, they may be used before definitions in this file or
defined in other files like 'struct iommu_ops;' field (Actually, i can
not find this field's
definition in this file). However, if it has been defined in other
header files, we need
not declare here, right?
--
Thanks
Harry Wei
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC]confusions about 'struct' define
2012-05-30 17:37 ` harryxiyou
@ 2012-06-01 9:30 ` Bernd Petrovitsch
2012-06-04 14:18 ` Sarbojit Ganguly
0 siblings, 1 reply; 7+ messages in thread
From: Bernd Petrovitsch @ 2012-06-01 9:30 UTC (permalink / raw)
To: kernelnewbies
Hi!
On Don, 2012-05-31 at 01:37 +0800, harryxiyou wrote:
> On Thu, May 31, 2012 at 1:20 AM, Gaurav Jain <gjainroorkee@gmail.com> wrote:
[...]
> > Those are forward declarations as they are being used in defining struct
> > bus_attribute. It's nothing special about GNU-C. That's the case for ANSI-C
> > too. Pretty standard.
These actually exists since K&R times.
> Hmmm.., that is to say, they may be used before definitions in this file or
> defined in other files like 'struct iommu_ops;' field (Actually, i can
Yes, that's the only reason. And you can't use it if you need the actual
size of that struct because the compiler doesn't know it (yet).
The main usage scenario is if you need a pointer to it.
> not find this field's
> definition in this file). However, if it has been defined in other
> header files, we need
> not declare here, right?
If you #include that other file, yes.
But it is not trivial in very large projects like the Linux kernel to
keep somewhat logical and clean and circular-free -h files.
And you also do not really want a separate .h file for each struct.
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
^ permalink raw reply [flat|nested] 7+ messages in thread* [RFC]confusions about 'struct' define
2012-06-01 9:30 ` Bernd Petrovitsch
@ 2012-06-04 14:18 ` Sarbojit Ganguly
0 siblings, 0 replies; 7+ messages in thread
From: Sarbojit Ganguly @ 2012-06-04 14:18 UTC (permalink / raw)
To: kernelnewbies
Foward declaration, that is.
You can vaguely compare it to function prototypes.
On 1 June 2012 15:00, Bernd Petrovitsch <bernd@petrovitsch.priv.at> wrote:
> Hi!
>
> On Don, 2012-05-31 at 01:37 +0800, harryxiyou wrote:
>> On Thu, May 31, 2012 at 1:20 AM, Gaurav Jain <gjainroorkee@gmail.com> wrote:
> [...]
>> > Those are forward declarations as they are being used in defining struct
>> > bus_attribute. It's nothing special about GNU-C. That's the case for ANSI-C
>> > too. Pretty standard.
>
> These actually exists since K&R times.
>
>> Hmmm.., that is to say, they may be used before definitions in this file or
>> defined in other files like 'struct iommu_ops;' field (Actually, i can
>
> Yes, that's the only reason. And you can't use it if you need the actual
> size of that struct because the compiler doesn't know it (yet).
> The main usage scenario is if you need a pointer to it.
>
>> not find this field's
>> definition in this file). However, if it has been defined in other
>> header files, we need
>> not declare here, right?
>
> If you #include that other file, yes.
> But it is not trivial in very large projects like the Linux kernel to
> keep somewhat logical and clean and circular-free -h files.
> And you also do not really want a separate .h file for each struct.
>
> ? ? ? ?Bernd
> --
> Bernd Petrovitsch ? ? ? ? ? ? ? ? ?Email : bernd at petrovitsch.priv.at
> ? ? ? ? ? ? ? ? ? ? LUGA : http://www.luga.at
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC]confusions about 'struct' define
2012-05-30 16:50 [RFC]confusions about 'struct' define harryxiyou
2012-05-30 17:20 ` Gaurav Jain
@ 2012-05-31 16:40 ` michi1 at michaelblizek.twilightparadox.com
1 sibling, 0 replies; 7+ messages in thread
From: michi1 at michaelblizek.twilightparadox.com @ 2012-05-31 16:40 UTC (permalink / raw)
To: kernelnewbies
Hi!
On 00:50 Thu 31 May , harryxiyou wrote:
...
> I have never seen struct define like
>
> "struct device;
> struct device_private;
> struct device_driver;
> [...]
> struct device_node;
> struct iommu_ops;"
This basically says that these structs exist and are defined somewhere. You
need this basically for things like this:
struct b;
struct a{
struct b *b_ptr;
};
struct b{
struct a *a_ptr;
};
The struct can only be dereferenced after it is defined. Also, the storage
size is unknown, so the same applies to inlining and sizeof().
-Michi
--
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC]confusions about 'struct' define
@ 2012-05-30 18:41 Rajat Sharma
0 siblings, 0 replies; 7+ messages in thread
From: Rajat Sharma @ 2012-05-30 18:41 UTC (permalink / raw)
To: kernelnewbies
This might be the case of cyclic dependency where header files defining
these structures are also including this .h file.
-Rajat
From: harryxiyou
Sent: 30-05-2012 23:08
To: Gaurav Jain
Cc: Greg-Kroah-Hartman; Harry Wei; kernelnewbies at kernelnewbies.org
Subject: Re: [RFC]confusions about 'struct' define
On Thu, May 31, 2012 at 1:20 AM, Gaurav Jain <gjainroorkee@gmail.com> wrote:
Hi Gaurav,
> Those are forward declarations as they are being used in defining struct
> bus_attribute. It's nothing special about GNU-C. That's the case for ANSI-C
> too. Pretty standard.
>
Hmmm.., that is to say, they may be used before definitions in this file or
defined in other files like 'struct iommu_ops;' field (Actually, i can
not find this field's
definition in this file). However, if it has been defined in other
header files, we need
not declare here, right?
--
Thanks
Harry Wei
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-06-04 14:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-30 16:50 [RFC]confusions about 'struct' define harryxiyou
2012-05-30 17:20 ` Gaurav Jain
2012-05-30 17:37 ` harryxiyou
2012-06-01 9:30 ` Bernd Petrovitsch
2012-06-04 14:18 ` Sarbojit Ganguly
2012-05-31 16:40 ` michi1 at michaelblizek.twilightparadox.com
-- strict thread matches above, loose matches on Subject: below --
2012-05-30 18:41 Rajat Sharma
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).