Search code examples
cexitc99termination

How to implement analogue of exit() functions? -std=c99


I'm writing a university project. Writing in standard C99. One of the requirements is the lack of exit(); function. Is it possible to implement a similar function? I tried to make a function that calls main with a minus argc to detect exit. It was a stupid attempt, because the first main continues.

Just the description of the project specified that the scores will be reduced for the use of exit by exit().I understand that it asks me to code running through pointers and returns an error in the return values ​​of the function. I'm more interested in the practice. Only for myself.


Solution

  • I think you misunderstood the requirement: They probably said something like do not use exit(). This does not mean you are supposed to implement your own exit(), quite to the contrary: they probably mean that the only exit-point of your program shall be the end of your main-function (or a return-statement within the main function) which is considered good programming style.