One way would be to compile them and then extract this information from
the object files. On a Unix system, this would probably be easiest to
do by parsing the output of nm(1). On my FreeBSD system, I'd do
nm *.o |grep '[0-9A-Fa-f]* [BCDGRS]' |cut -d ' ' -f 3
Testing this, it appears that it will miss global constants, i.e., a
`const' variable with external linkage, because they get stored in the
.text section. Changing the above regexp to '[0-9A-Fa-f]* [BCDGRST]'
would include them, but would also include all functions with external
linkage, which might not be what you want. However, it's a start, I
guess.
It also misses the global variables which have not been
included in the particular build configuration. If you're
auditing source code, then this:
#if defined(__MIPS__) && defined(__GCC__) && defined(PROFILING) && (PROFILING>2)
int tally;
#endif
definitely still has a global variable, even if you've never built
for MIPS for years. The solution, however, depends a lot on how
sane and strictly adhered to your coding standards are. Again,
I know that a grep would solve the problem on my own source code
trees, as my global variables are always declared in the same way,
and in a way that functions, function-local variables, function
parameters, struct members, ... aren't,
Phil
--
I tried the Vista speech recognition by running the tutorial. I was
amazed, it was awesome, recognised every word I said. Then I said the
wrong word ... and it typed the right one. It was actually just
detecting a sound and printing the expected word! -- pbhj on /.