Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Emulator basics: a stack and register machine (eatonphil.com)
145 points by eatonphil on June 9, 2019 | hide | past | favorite | 4 comments


> If you know why our macOS users use _main I'd love to know.

You'll find this on Linux, too. You'll notice the compiler (on POSIX systems?) prefixes your symbol names with _ since The Dawn Of Time.


The leading underscore on MacOS is part of the Mach-O standard [1]. This was inherited from a.out which really wasn't much of a standard per se but rather just a collection of a.out implementations [2]. Mach-O (1987) predated ELF (1993) and the later ELF abandoned the underscore as unnecessary.

[1] http://math-atlas.sourceforge.net/devel/assembly/MachORuntim...

[2] https://www.nasm.us/doc/nasmdoc9.html


It actually doesn't prefix all symbol names as such! The underscore prefix indicates the cdecl calling convention specifically; other calling conventions have their own name mangling schemes.

Edit: I had a nagging feeling that I was forgetting something, and I was. This is only a Windows convention, not a more universal thing.


I've never seen this on Linux. There is a gcc option -fleading-underscore, which is meant for "legacy assembly code".




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

Search: