2

Problem is - I have to implement my own exit(status) with setjmp and longjmp. Maybe someone could give some pointers?

Marc
  • 16,170
  • 20
  • 76
  • 119
Jānis Gruzis
  • 905
  • 1
  • 10
  • 25
  • 2
    [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – Some programmer dude Nov 03 '12 at 15:57
  • @JoachimPileborg I have tried nothing since only implementation that is allowed is with setjmp/longjmp and I really cant imagine how to create solution from these functions. Well what I have done is, I searched for exit implementation in kernel source, but there was a lot of stuff which probably does the same thing but with different methods. (More precisely I was looking at _exit()) – Jānis Gruzis Nov 03 '12 at 16:03
  • You might like to read this: http://stackoverflow.com/q/1733649/694576 – alk Nov 03 '12 at 16:25

1 Answers1

3

The only solution I think of right now, is to call setjmp early in main, and then create a MyExit function which does a longjmp to the setjmp in main and does a return with some value (provided from the longjmp call).

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • This looks like a valid solution, I didn`t notice, that I can put macros in main function. Probably that is the place where I can put setjmp and control return in case of jumping back. Thank you. – Jānis Gruzis Nov 03 '12 at 16:33
  • What macros are you talking about? – Barmar Nov 03 '12 at 17:02
  • I know what macros are, I just don't see what it has to do with this question or answer. `setjmp()` is a function (or it can be treated as if it is). – Barmar Nov 03 '12 at 17:18
  • @Barmar If you put macros in beginning of main (which contains setjmp and other constructions) you can return to the beginning with myExit and return nonzero code returned by setjmp. The thing is, in beginning I thought that I have to do this without macros. – Jānis Gruzis Nov 03 '12 at 17:45