From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
To: Bernd Petrovitsch <bernd@petrovitsch.priv.at>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [Q] compiler no longer warning about undeclared struct?
Date: Thu, 28 Jul 2011 12:16:04 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.64.1107281211120.20737@axis700.grange> (raw)
In-Reply-To: <1311847409.3897.23.camel@thorin>
On Thu, 28 Jul 2011, Bernd Petrovitsch wrote:
> Hi!
>
> On Mit, 2011-07-27 at 19:57 +0200, Guennadi Liakhovetski wrote:
> [....]
> > I just ran across a driver in the kernel (drivers/media/video/ov2640.c,
> > struct ov2640_priv::info), that does something like
> >
> > struct xx {
> > struct yy *y;
> > };
> >
> > static void z(void)
> > {
> > struct xx *x;
> > void *p;
> >
> > x = ...;
> > p = ...;
> > x->y = p;
> > }
> >
> > where "struct yy" is nowhere declared, and the compiler happily swallows
> > this... Shouldn't it complain? Didn't it complain before?
>
> It's normal C behaviour: As long as the compiler doesn't need the size
> or fields of struct yy, it doesn't complain that it doesn't know the
> details.
I always thought you need forward declarations for those, as in
struct yy;
before declaring struct xx above.
> Otherwise you could not define recursive structures as in
> ---- snip ----
> struct a {
> struct *b;
> };
> struct b {
> struct *a;
> };
> ---- snip ----
I would add a "struct b;" forward declaration before "struct a".
Thanks
Guennadi
---
Guennadi Liakhovetski, Ph.D.
Freelance Open-Source Software Developer
http://www.open-technology.de/
next prev parent reply other threads:[~2011-07-28 10:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-27 17:57 Guennadi Liakhovetski
2011-07-28 10:03 ` Bernd Petrovitsch
2011-07-28 10:16 ` Guennadi Liakhovetski [this message]
2011-07-28 11:08 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.1107281211120.20737@axis700.grange \
--to=g.liakhovetski@gmx.de \
--cc=bernd@petrovitsch.priv.at \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®