0

Hello sometime back I came across a command in Linux which prints in a file with the same name as that of the sourcecode filename but different extension,the detailed usage of sizes of the structures defined in the source code ...please let me know about any such commands

Thanks

  • 1
    Can you elaborate your question? What do you mean by `prints in a file`, `sourcecode filename` and `detailed usage of sizes of the structure`? – jaypal singh Dec 25 '11 at 09:01
  • It is a reasonable guess that `magic_command sourcefile.c` generates some other file `sourcefile.x` that contains some information about the size of the various structures in the file. It would be interesting to know what the size information is and what else, if anything else, is printed in the file. – Jonathan Leffler Dec 25 '11 at 09:15
  • hello @Jonathan Leffler ..yes exactly ..its for analysis of the source file you provide to the compiler with some particular switches/options and the output file(with same name as source code file but different extension) contains details in comments about the various sizes for each of the stuctures etc ...I came across such a useful command and now I regret for not noting it down.I was looking for information regarding structure padding I guess and then I came across this one post (not sure which site) where the poster posted this command along with explanation to some code.Please let me know – user1115175 Dec 25 '11 at 09:40
  • [Linux C: Easy & 'pretty' dump/printout of structs (like in gdb) - from source code?](http://stackoverflow.com/q/3311182) & [A way to find the size and location of padding in a struct?](http://stackoverflow.com/q/3294010)/ might help – another.anon.coward Dec 25 '11 at 10:11
  • hello @another.anon.coward your reply to my post is of little help.I was not able to find that specific command and that command was not about related to GDB ..if I am not wrong ..anyways please let me know if you find something specific and better..thanks – user1115175 Dec 25 '11 at 10:19

1 Answers1

1

My best guess is you are talking about nm which lists symbols from object files. A quick example:

file test.c

int int_array[10];
double double_array[10];

int main()
{
   int_array[0] = 0;
   double_array[0] = 0;

   return 0;
} 

Build an object file :

$ gcc -c test.c

Now list symbols with size information:

$ nm -S test.o

This prints something like this on my macbook:

0000000000000040 n EH_frame0
0000000000000050 C _double_array
0000000000000028 C _int_array
0000000000000000 T _main
0000000000000058 N _main.eh

Check the nm manpage for further information (http://linux.about.com/library/cmd/blcmdl1_nm.htm)

gilligan
  • 488
  • 3
  • 15