How to count the number of global variables in C++ with a program that I can run with Grep?
+4
A:
Grep has no knowledge of the syntax or the grammar; it operates on lines. I don't think this is possible.
Here's a snippet of some code I'm working on:
int count;
Can you tell me if it's global?
Jurily
2009-12-14 23:50:34
More fun: `int foo(bar);`.
MSalters
2009-12-15 10:57:31
A:
You might be able to grep something in the artifacts of compilation such as listing files or object files.
Tony van der Peet
2009-12-14 23:53:57
+5
A:
A better method is to have your compiler print a map file. Most map files list all the global variables and their locations. If you're lucky, the map file may even indicate which translation unit the global variable belongs to.
Thomas Matthews
2009-12-14 23:54:13