List global variables in a C program

故事扮演 提交于 2019-12-05 22:37:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!