问题
Is there a tool around that will list all the global variables in a C program? More specifically, is there a simple commandline tool that will do this, i.e. not a heavyweight IDE, CASE, graphical toolkit system etc., but just something that can be run like foo *.c
?
回答1:
If you happen to compile the file on most unixes you have nm
that just lists you all linker symbols. These symbols are classified in different groups (a bit platform dependent) so you should easily find out which the variables are.
回答2:
ctags -R -x --sort=yes --c-kinds=v --file-scope=no file "c:\my sources" > c:\ctagop.txt
回答3:
Try ctags. Or, gcc with -aux-info
. There is also gccxml and libclang but those two aren't very simple.
回答4:
ctags -R -x --sort=yes --c-kinds=v --file-scope=no <path to dir containing source>
Credit to Gaurav M. Bhandarkar for the basic solution. The "file" before the path to the source is not necessary. As shown by Gaurav M. Bhandarkar, the output can be dumped to a file using ">"
来源:https://stackoverflow.com/questions/6082950/list-global-variables-in-a-c-program