Reputation: 105
I have this excersice in my university, and we are not allowed to use stdlib. I used exit in some places and for some reason visual studio did not yell at me for not including stdlib. Now I'm compiling on the university servers and obviously it's not working (I did not know exit belongs to stdlib).
The question : How is the exit function defined ?
Upvotes: 1
Views: 275
Reputation: 145919
You can call exit
without having to include stdlib.h
: just put the exit
declaration at the top of your source file:
void exit(int status);
Now the objective of your exercise is probably to not use any function from stdlib.h
.
If you aren't prohibited from using signal.h
, then just call raise( SIGTERM )
instead of exit.
Upvotes: 5
Reputation: 134396
we are not allowed to use stdlib.
Well, a quick workaround may be, use #include <unistd.h>
and use _exit()
/ _Exit()
.
Otherwise, you're free to replace exit()
call with return
statement, as I mentioned in my comment above.
Upvotes: 1
Reputation: 9354
I imagine that the intent is not to call anything from <stdlib.h>
so hacking around by doing 'extern' is probably not what is desired.
So all you can do is to return a value from main()
at the appropriate point.
Upvotes: 2