Page 1 of 1

C: File-scope visibility of identifiers

Posted: Fri Nov 21, 2003 11:39 am
by Solar
Help out a C++ vet who's out of his fishing grounds...

Let's say I write a "C" header file, X.h. This header in turn includes another, Y.h.

I want to avoid the stuff from Y.h "leaking out" of X.h - if someone includes X.h, he should only see the identifiers from X.h, not those from Y.h.

I know the answer is probably trivial, but my brain stops dead after spitting out "anonymous namespace" - which, of course, is C++, not C...

Re:C: File-scope visibility of identifiers

Posted: Fri Nov 21, 2003 2:49 pm
by Tim
You can't.

How you deal with this depends on what X.h needs from Y.h. As a C++ programmer, I assume you know that this works:

Code: Select all

/* X.h */

struct astruct
{
    /* anotherstruct defined in Y.h */
    struct anotherstruct *fred;
};
However, this won't:

Code: Select all

/* X.h */

struct astruct
{
    /* anotherstruct defined in Y.h */
    struct anotherstruct fred;
};
In the second example, X.h really does need the definition of anotherstruct in order to make the definition of astruct work.

Re:C: File-scope visibility of identifiers

Posted: Sat Nov 22, 2003 1:48 am
by Solar
Thanks.