Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In C (and C++) main is always a function with zero parameters, two parameters as described in detail, or some implementation-specific set of parameters. ANything else is undefined behaviour.

In other words, you can write `main` as anything you want, and it might do something when presented to a C compiler, and that might do something when linked through the system linker, but it's not C code.

Doing something that's by definition incorrect and having it maybe do something somewhere sometimes, or maybe not, is not really all that impressive when you think about it.



> Doing something that's by definition incorrect and having it maybe do something somewhere sometimes, or maybe not, is not really all that impressive when you think about it.

See I would have called this hacking, which here on Hacker News is its own special kind of impressive.


It's hacking, sure. Just like using a hex editor to enter machine code directly. It's not C code, though, despite what the author claims, and it's not showing some clever way to hack C code that makes the author look Klever. SO go ahead an be impressed some something that isn't what it claims to be and doesn't do what it claims to do.


Of course it's C code. It parses, and compiles, giving undefined behavior.

If C wanted to insist that main is a function, it could. That could be in the standard, and then these clever hacks wouldn't compile.

So no, you're dead wrong about that claim. So I'll go ahead and not be impressed with your commentary.

Of course a standards compliant C compiler could give you nasal demons, or delete your root directory, so it's not the sort of thing one should push to prod on a Friday.

It's just a hack.


You could make main() a standard C function that merely calls this machine code hack function.


You could. But `main()` would still then be a function, no?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: