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...
C: File-scope visibility of identifiers
C: File-scope visibility of identifiers
Every good solution is obvious once you've found it.
Re:C: File-scope visibility of identifiers
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:
However, this won't:
In the second example, X.h really does need the definition of anotherstruct in order to make the definition of astruct work.
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;
};
Code: Select all
/* X.h */
struct astruct
{
/* anotherstruct defined in Y.h */
struct anotherstruct fred;
};
Re:C: File-scope visibility of identifiers
Thanks.
Every good solution is obvious once you've found it.