PROGRAM WITHOUT MAIN!!!

1
2
3
4
5
6
7
8
9
10
#include<stdio.h>
#define hack(y,o,k,a,l,x) a##l##o##k
#define begin hack(t,i,n,m,a,x)

int begin()

{
printf(" hello ");
getchar();
}
Last edited on
I don't know what you think that's doing, but by the time the compiler gets to that code main is sitting there, plain as day.
closed account (Dy7SLyTq)
main actually isnt where it starts. its just the entry point that can be changed. the win api does it. point is you can actually have a program without int main(). but that code shouldnt compile, at least not with gcc, because your not providing any entry point at all
@DTSCode
Take a closer look at the defines.
closed account (Dy7SLyTq)
oh my bad i didnt see chars were passed to hack. i thought those were variables to pass. so while what i said is true, this will compile because despite what op says, it does have a main(), just hidden by a macro
point is you can actually have a program without int main(). but that code shouldnt compile, at least not with gcc, because your not providing any entry point at all


Any compiler will compile that code, even without any main(). It is the linker which will complain about some "undefined reference".

PS - It is possible to write a C program which does not use any CRT functions and does not depend on it, with no main() at all.
closed account (Dy7SLyTq)
Any compiler will compile that code, even without any main(). It is the linker which will complain about some "undefined reference"

maybe with your compiler. it doesnt for my compiler. it generates a bunch of errors before the linker starts.

edit:
PS - It is possible to write a C program which does not use any CRT functions and does not depend on it, with no main() at all.

and once again idk what compiler your using, but mine certainly doesnt let you. and dont quote me on this, but i had an argument with someone a long time ago and i think they said it was against the standard
Last edited on
@naraku9333 , @DTSCode You Got It Right!
Topic archived. No new replies allowed.