title: C illegal instruction
body: <p>Below is a print out of a c program I wrote, a demonstration of me running it, and finally some information on my compiler.</p>
  <pre><code>➜  illegalInstructionDebug cat illegal.c
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  
  void func(int* Z){
      Z[-11] = acos(2);
  }
  
  int main(){
      fflush(stdout);
      printf(&quot;&quot;);
      fflush(stdout);
      int X[3];
      int Z[3];
      for (int n=0;0!=0;);
      func(Z);
  }
  ➜  illegalInstructionDebug gcc illegal.c; ./a.out
  [1]    28836 illegal hardware instruction  ./a.out
  ➜  illegalInstructionDebug clang --version
  Apple clang version 11.0.3 (clang-1103.0.32.62)
  Target: x86_64-apple-darwin19.6.0
  Thread model: posix
  InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  ➜  illegalInstructionDebug
  </code></pre>
  <p>I was writing a program an encountered an illegal instruction error, which is something I had never seen before, so I decided to attempt to find a minimal working example so I could figure out what distinguished it from a segfault or some other kind of error. Oddly, it seemed minor changes in the program would return it to giving a segfault instead of an illegal instruction error. Nonetheless, I have managed to reduce the program down substantially to a smaller working example. That being said, the program is still rather large for a minimal working example.</p>
  <p>My questions are first why am I getting an illegal instruction error and second what is an illegal instruction error. Also if this error is specific to my machine that would interest me also. There are a lot of strange attributes to this program. For example, it seems the number -11 is required to cause the error.</p>