List global variables in a C program

2019-04-07 11:26发布

问题:

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:

Try ctags. Or, gcc with -aux-info. There is also gccxml and libclang but those two aren't very simple.



回答3:

ctags -R -x --sort=yes --c-kinds=v --file-scope=no file "c:\my sources" > c:\ctagop.txt