Re:Main is usually a function, so when is it not? (2015)
by gumby on Sunday September 10, 2017 @11:49AM
(#15212706)
The program entry point is actually _start (which does some setup and later calls main()) so for even more extreme TA befuddlement, write a program that doesn't even call main()!
[ Parent
| on HN ]
Re:Main is usually a function, so when is it not? (2015)
by mmjaa on Sunday September 10, 2017 @12:59PM
(#15213065)
int noMain() __attribute__ (constructor);
int noMain() {
printf("Goodbye, main()");
} // &etc.
Re:Main is usually a function, so when is it not? (2015)
by dfox on Sunday September 10, 2017 @03:37PM
(#15213900)
This actually would not link, because _start() or something it calls into (depending on implementation of CRT on given platform) would contain unresolved reference to main. (and goven the fact that all this CRT startup code is usually one .o, you cannot just patch out the part that calls main(), you have to replace it completely)
On the other hand something around the lines of:
void _start(){
write(1, "Hello world\n", 12);
exit(0);
}
should probably work, given that you link it without CRT startup code (ie. gcc -nostdlib)
Re:Main is usually a function, so when is it not? (2015)
by im3w1l on Sunday September 10, 2017 @07:18PM
(#15214844)
Now for more confusion, have a main function that _start doesn't call.
Now for even more confusion, have the main function (which never runs) call the _start function.