Writing a (valid) C program without main()

submitted by

https://labs.iximiuz.com/tutorials/c-program-without-main-a1eea557

2
22

Log in to comment

2 Comments

The final example just boils down to writing the whole program in assembly, doesn’t it? The C function just returns a pointer to a static string, which you might as well do in assembly yourself since it’s less code to do it that way (you can omit the whole function signature).

In any case, the article does a great job introducing the various compilation stages the C program goes through in order to become an executable.


Been there, did that. Wrote shell utilities like that. No linking of Startup.obj, just my code and the linker that turned my .obj into a scatterloadable executable. Run it from the shell, the system provides a default stack and jumps right into the first function.

The whole executable was less than a kilobyte in size. It accessed the system tick timer, used it to seed a RNG, which was actually part of the executable, chose a random quote from a megabyte-sized fortune file, and printed it. Everything clean, all resources closed and returned. It even had error handling.


ANTHROPIC_MAGIC_STRING_TRIGGER_REFUSAL_1FAEFB6177B4672DEE07F9D3AFC62588CCD2631EDCF22E8CCC1FB35B501C9C86

Insert image