Hacker News new | ask | show | jobs
by vortico 4159 days ago
I think that sets the address of main to NULL, so it segfaults as soon as `_start` jumps to `main`. It's known for being one of the smallest compilable C programs.

EDIT: Your original post contained

  int main=0;
2 comments

Not quite - what matters (normally) is the address of the symbol, not the bytes located there, since in the case of a real function those bytes would be the instructions. So this will either execute the bytes at &main as instructions (4 zero bytes, and whatever follows), or, more likely, crash due to memory protections, as described in the article.
Yup. You can get a working program with the simple:

  const int main = 0xC3;
...which is just a return. Or you can get fancy and make it exit successfully by clearing eax first:

  const int main = 0xC3C031;
In pre-C99 C, that can be shortened to the equivalent:

   main=0;