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
?
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.
ctags -R -x --sort=yes --c-kinds=v --file-scope=no file "c:\my sources" > c:\ctagop.txt
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.
to list all globals (linux/gnu) for program 'foo': if the program is compiled with -g (gcc -g -o foo main.c) nm foo | grep " B " | sed -e "s/^[^B]*B//g" will list all globals, nm lists the objects, grep seperates out the global variables, and sed cleans up the presentation.
Actually most stuff I compile is with Makefiles so it is CFLAGS=-g -pg -Wextra in the Makefile, so the executable can be scanned until a 'make dist'
user1717828 on stackechange provided the grep template
© 2022 - 2024 — McMap. All rights reserved.