I want to have a list of all the variables I have defined in a code in C. Is there a built-in method in C to perform this task?
I want to have a list of all the variables I have defined in a code in C. Is there a built-in method in C to perform this task?
If you want to use the list in C program where variables are defined directly, you have to make a list(maybe a string array) and add name to the list every time you are defining a new variable. And there is no built-in method in C to get the variable name base on its address, because variable names will be totally erased after compile in the range of itself. So names in list have to be typed manually.
Or you can use some tools to screen variables out of program, a example using ctags on Linux bash is:
ctags --c-kinds=lv -f - <YOUR_C_SOURCE_FILE_NAME> | cut -d$'\t' -f1
ctags can also get the complete definition statement. Read the manual of ctags for more details.
Is there a built-in method in C to perform this task?
No, there is not. C language is a language without reflection. It is not possible to inspect it's own source code.
You may write a parser in C that will parse the source code of your program and extract the information from that.