Re:Main is usually a function, so when is it not? (2015)
by samatman on Monday June 14, 2021 @05:49PM
(#27508749)
> 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.
Re:Main is usually a function, so when is it not? (2015)
by bregma on Tuesday June 15, 2021 @03:24PM
(#27520253)
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.
Re:Main is usually a function, so when is it not? (2015)
by samatman on Tuesday June 15, 2021 @03:39PM
(#27520452)
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.
Re:Main is usually a function, so when is it not? (2015)
by scintill76 on Monday June 14, 2021 @03:33PM
(#27507144)
You could make main() a standard C function that merely calls this machine code hack function.
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.