David Resnick wrote:
> wrote:
> > Hello all,
> >
> > I suppose the title says most of it... this has happened to me a couple
> > of times with large C projects. You inherit a large source tree with a
> > complex set of Makefiles. In this environment, what is the easiest way
> > to find out where, say, a certain struct is defined? This isn't a
> > problem if the label is distinctive but in my current problem, I am
> > trying to find out where a BOOL convenience type has been defined -
> > when I grep the tree, there are defs for it all over the place - which
> > one is my current compilation using?
> >
> > Does this question make any kind of sense? Coming from java with its
> > explicit package-directory mapping this sort of thing just seems
> > incredibly hard to keep non-confusing in C.
> >
> > Cheers,
> > cam
>
> A good way is, if your implementation supports it, to request that an
> intermediate file be generated during compilation after the
> preprocessing
> step. For example, the -E flag of gcc. Exactly how to do this or
> whether you can on your system is not on topic here, so you should
> ask in a newsgroup appropriate for your compiler/OS.
>
> -David
A few other options if you can't take my other idea (make a
preprocessed file)
1) put in a test if it is defined after each include:
#include "foo.h"
#if defined(BOOL)
#error BOOL is defined in foo.h
#endif
Of course, you then need to go into foo.h and look at is includes and
so forth, can be irritating, but it should work eventually.
2) #define the thing after all the includes. Your implementation MAY
give you a very helpful hint about where the original definition
resides. Or it may not. Example of what a helpful compiler might tell
you:
temp(889)$ cat foo.c
#include "stdio.h"
#define NULL 1
int main(void)
{
puts("hello, world");
return 0;
}
temp(889)$ gcc -Wall -ansi -pedantic -o foo foo.c
foo.c:2:1: warning: "NULL" redefined
In file included from /usr/include/_G_config.h:14,
from /usr/include/libio.h:32,
from /usr/include/stdio.h:72,
from foo.c:1:
/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/include/stddef.h:402:1:
warning: this is the location of the previous definition
-David