1

I know object code is the code after the compilation phase which is present in a object file(eg:aaa.obj). What is this file? Contains Machine Instructions? If so why can't I see any 0's and 1's in that file. Please help me out.

prog481
  • 319
  • 1
  • 4
  • 12

1 Answers1

4

What's an object file in C?

An object file is the real output from the compilation phase. It's mostly machine code, but has info that allows a linker to see what symbols are in it as well as symbols it requires in order to work. (For reference, "symbols" are basically names of global objects, functions, etc.)

A linker takes all these object files and combines them to form one executable (assuming that it can, ie: that there aren't any duplicate or undefined symbols). A lot of compilers will do this for you (read: they run the linker on their own) if you don't tell them to "just compile" using command-line options. (-c is a common "just compile; don't link" option.)


If so why can't I see any 0's and 1's in that file.

You are confusing object file concept with executable file concept. The thing is that object file contains compiled code and instructions for the linker (program building one executable file from one or more object files). The output of the linker program is actually executable file which contains expected by you zeros and ones.

Community
  • 1
  • 1
Krystian Sakowski
  • 1,613
  • 14
  • 20
  • even executable files don't show up 0's and 1's, instead some non-understandable scripts.Why? – prog481 Sep 02 '15 at 09:29
  • Yes, your computer works with 0 and 1's (the bits) but in reality it uses sequence of that. 8bit is one byte, and most systems use 8bytes at a time (a 64 bit system). As most people prefer text, and 8bits will do for western text (ascii), most editors try to show everything as ascii text. You will see many characters, as most of the 256 combinations in a byte are used for a char. But unless the file is text, you will see no (hardly) real words. To see details, you need a special program, like hexdump, od, etc. most Unix system have them, on windows it is sparse. – Albert Sep 02 '15 at 21:17