title: File format for executable on Mac OS X
body: <p>I am attempting to (one step at a time) build my own copy of Forth to run on Mac&nbsp;OS&nbsp;X.</p>
  
  <p>I currently have a version of Forth running on Apache and localhost in PHP, Ruby, and Python.</p>
  
  <p>I want to make a version of Forth in C that will create a native executable version of Forth that can make its own native executable files of any compiled Forth code. Sorry about the semi-recursive sentence. My goal is to start in C and end up with my own Forth compiler (no longer running in any C code).</p>
  
  <p>My starting point is to attempt to get a minimal test program to run as a binary executable for Terminal. Once I can understand what the existing C compiler is doing, I can modify its methods for my own purposes.</p>
  
  <p>I created a small "hello world" program in C and ended up with an executable file of 8,497 bytes, which consisted mostly of 0x00 arrays (presumably buffers). My guess is that the entire stdio library was included.</p>
  
  <p>Next, I created the smallest possible C program I could think of (other than a completely null program -- I wanted to be able to find my code in the resulting hex):</p>
  
  <pre><code>int main(void)
  {
      char testitem;
      testitem = 'A';
      return -1;
  }
  </code></pre>
  
  <p>That should have given me the barest possible overhead with the storage of the ASCII A and the return value of all ones being easy to find.</p>
  
  <p>Instead, I ended up with a file of 4,313 bytes. There were four locations with the 0x41 (ASCII 'A'), but none were part of a MOV immediate byte instruction. Presumably the 0x41 was stored as constant data and loaded with a different MOV instruction.</p>
  
  <p>Again there were a lot of 0x00 arrays (3,731 bytes, or all but 402 bytes). Presumably there is some kind of header data in the object file (which does run correctly in Terminal and does signal -1) and who knows what else.</p>
  
  <p>At the moment I am not concerned with having an application bundle -- running in Terminal is my short term goal. Once I have this first step working, I can move on to a full application.</p>
  
  <p>Any suggestions on how to determine what I need to have in the object file for it to correctly work as a Terminal tool?</p>