views:

297

answers:

3

When compiling, C produces object code before linking time. I wonder if object code is in the form of binary yet? If so, what happened next in the linking time?

+4  A: 
Jacob
A: 

Yes, object code is usually in binary form. Just try opening it in your favorite text editor.

You can learn what linkers do here or here.

Employed Russian
A: 

Object files as produced by the C compiler essentially contain binary code with holes in each place where an address should go that is yet unknown (addresses of function from other files -- including libraries -- called, addresses of variables from other files that are accessed in this one, ...).

It also contains a table indexed by symbol names ("x" or "_x" for variable x, "f" or "_f" for function f). For each such symbol, there is a status code ("defined here", "not defined here but used", ...) and the addresses of holes in the binary code that need to be filed with each address when it becomes known.

If you are using Unix (or gcc on Windows), you can print the later table with the command "nm file.o".

Pascal Cuoq