Main is usually a function, so when is it not? (2015)

# · 🔥 224 · 💬 63 · 2 years ago · jroweboy.github.io · ColinWright · 📷
The idea for this trick I will explain how to accomplish came from a blog with the name main is usually a function which got me thinking about when would main not be a function? Let's find out then! Apparently in 1984, a strange program won the IOCCC where main was declared as a short main[] = and somehow this did stuff and printed to the screen! Too bad it was written for a whole different architecture and compiler so there is really no easy way for me to find out what it did, but judging from the fact that it is just a bunch of numbers, I can surmise that the numbers there are just the compiled binary of some short function and the linker when looking for the main function just throws this in the place of it. With our hypothesis in place, that the code for the program is just the compiled assembly of main function represented as an array, let's see if we can replicate this by making a small program and seeing if we can do that. C:1:6: warning: 'main' is usually a function. In our case, we can only fill in code for the main function, so anything that gets placed in the data section is a no go. We need to find a way to get the string "Hello world!" inside the main function and reference it. C:1:11: warning: 'main' is usually a function.
Main is usually a function, so when is it not? (2015)



Send Feedback | WebAssembly Version (beta)