| Jeff Abrahamson on Sun, 8 Dec 2002 22:40:08 -0500 |
|
On Sun, Dec 08, 2002 at 08:12:33PM -0500, Will Dyson wrote:
> Jeff Abrahamson wrote:
> >>
> >>> int foo(struct bar *b);
> >>>
> >>> typedef struct bar {
> >>> int a;
> >>> } Bar;
> >>>
> >>> foo(Bar *b)
> >>> {
> >>> return 0;
> >>> }
>
> >My read of K&R is that, as long as you don't need to know the size of
> >the struct pointer, you don't need to have the definition of the
> >struct available in the current translation unit.
> >
> >The real issue here, since I could just #include bar.h, is that I
> >don't want to #include extraneous files. It slows compilations, risks
> >breaking data abstraction, and risks creating circular dependencies.
>
> What you need is a forward declaration of struct bar; You are correct that
> it does not need the definition, but it must know that struct bar is
> declared.
Yes, that's it.
I was under the mistaken impression that forward declarations were
neither required nor permitted by the ansi spec. Admittedly this left
a quandary, above.
Thanks.
--
Jeff
Jeff Abrahamson <http://www.purple.com/jeff/>
GPG fingerprint: 1A1A BA95 D082 A558 A276 63C6 16BF 8C4C 0D1D AE4B
Attachment:
pgp8kOLurnzrg.pgp
|
|