2 ms·
> according to the C standard, 'main' is not a reserved identifier! In fact, main() is just a convention of libc. You can have C without libc. (Such as when wr
by derefr 9y ago
> according to the C standard, 'main' is not a reserved identifier!
In fact, main() is just a convention of libc. You can have C without libc. (Such as when writing a kernel!)
Now, attempting to link a standalone executable without a '_start' symbol, on the other hand...
- shakna 9y ago> In fact, main() is just a convention of libc. No, it's not just a convention. 'main' is defined as the execution entrypoint in at least the C11 [0], C90 [1] standards. Both have both these forms defined: int main(void) {} int main(int argc, char* argv[]) {} You don't have to follow that convention, but then it becomes implementation-defined behaviour. C without libc can still expect to have a main. One doesn't imply the other. It's just without a main, you also have to manually link to _start as well. [0] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf [1] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
- prattmic 9y ago> Now, attempting to link a standalone executable without a '_start' symbol, on the other hand... GNU ld and gold both support --entry to change the entry point. Alternatively, you can specify it in your linker script. https://gist.github.com/prattmic/1f3618025aab52b0e90e88445b6fc7d4 https://gist.github.com/prattmic/1f3618025aab52b0e90e88445b6... $ gcc -nostdlib -ffreestanding -Wl,--entry=foobar -o main main.S $ ./main; echo $? 42