tags:

views:

89

answers:

5

hi,

i want to print the variables that are used in my C code .Its a 19KB file,so lot of variables are used in it.

i know its not so easy..b'z we donno whre my compiler puts this details..(debug info?..)

i am working in gcc ( Redhat (shrike))..

Renjith G

A: 

You could use the Print button on the keyboard.Make sure you have the printer connected.

abmv
A: 

You could compile and check in the executable. check the file-type, if it is elf, then you can use "readelf --symbols --wide myfile" and grep for OBJECT.

stefaanv
Variables may not be exported.
xtofl
thats fie enough..but i want to print the variable names from ma program itself.
+1  A: 

Maybe you mean something like the linux nm command, which lists symbols from an object file.

Yuval F
+1  A: 

You could run a regex similar to this on the source code:

(const *)? *(int|double|float|char) *(const *)? *(\* *)*(const *)? *;

Won't catch user defined types but if its a short enough code, you could add the relevant types manually.

Edit: forgot the ; at the end

Blindy
+1  A: 

Run ctags on your sources, then read the output tags file.

This will be a list of all visible identifiers (and possibly static ones too, depending on ctags options), the files they are defined in, and the location within the file.

This does not index local variables.

ephemient
+1 and a recommendation of ectags, an improved alternative.
Tadeusz A. Kadłubowski
My link does go to Exuberant-ctags's homepage :)
ephemient