J
Jroweboy
jroweboy.github.io · Personal blog · on HN since 2015
Jroweboy is a programmer who wrote a post on cases where main in C is not a function, using assembly tricks.
What HN saysHN commenters link the 2015 post as an entertaining C oddity and question whether its tricks still work with modern compilers.
18HN people shared it
7linked it in comments
11stories submitted
713story points
3 years agolast shared
2015people per year2026
Most-shared posts
- 1Main is usually a function – when is it not?18 people · 713 points · first shared 2015 · 65 comments on HN
What HN people wrote when they linked it
Teknoman117 · 2023-03-17
Makes me think of the "when is main not a function" article from 2015:
http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-function…
foota · 2021-12-30
You may be thinking of https://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-functio…
andreareina · 2020-08-30
Might have to make code const: http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-function…
robinhouston · 2020-08-30
The author says “I tried to define ‘main’ as an array of shorts with a modern compiler and it did not like that one bit”, but without saying which modern C compiler or what it didn’t like about it.
This sort of trick should still be possible with modern compilers. GCC has the charming warning
warning: ‘main’ is usually a function [-Wmain]
if main is declared as something other than a function.
Here’s someone who got it to work in 2015, anyway: http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-function…
signa11 · 2018-09-10
on similar lines, i find this http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-function… quite entertaining !
lfowles · 2017-09-08
Very similar, here's main() as an array
http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-function…
xlii · 2022-03-09
I’m disappointed. I expected some obscure edgecase (like “Main is usually a function…” [1]) but instead that’s about scope handling, contract design and responsibility shift.
“Hello world” method simply calls an API to a text interface. It uses simple call, to a simple interface that is expected to be ever present. I don’t find any bug there. It won’t work if such interface isn’t available, is blocked or doesn’t exist. It won’t work on my coffee grinder nor on my screwdriver. It won’t work on my Arduino because there is no text interface neither.
Of course, one could argue that user might expect you to handle that error. That’s all about contracts and expectation. How should I deal with that? Is the “Hello world” message such important that the highest escalated scenario should be painted on the sky? I can imagine an awkward social game where we throw each other obscure challenges and call it a bug.
It’s nitpicking that even such simple code might fail and I get it. It will also fail on OOM, faulty hardware or if number of the processes on the machine hit the limit. Maybe some joker replaced bindings and it went straight to 3D printer which is out of material? _My expectations_ were higher based on the title.
Now allow me to excuse myself, I need to write an e-mail to my keyboard manufacturer because it seems like it has a bug which prevents it from working when slightly covered in liquid coffee.
[1]:…