UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » setjmp() and longjmp()

#1 2007-08-22 09:46 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: setjmp() and longjmp()

when I read the APUE2 book,I am very puzzle with the setjmp() and the longjmp() functions, when we should use these two functions? and under what situations we use them? what are the effects when we use them in our programs?how do I decide the second parameter in the longjmp()?
  Best wishes

Offline

#2 2007-08-22 01:25 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: setjmp() and longjmp()

You  don't use them, so don't worry about it.

It's one of those things that you'll know when to use them, and how and what for, and if you are at that point, you'll know everything you need already.

If you have a specific question just ask it, but answering such generic clueless questions isn't very useful.

Offline

#3 2007-08-22 01:43 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: setjmp() and longjmp()

Yes, exactly: don't use them unless you simply can't avoid it...  They're horrible and
ugly...  They are essentially long-distance "goto"s...  And, like goto, they have very
few good, legitimate uses...  (In fact, there are a lot more for goto than *{set,long}jmp()...)

But, as for what value to pass *longjmp(), the point is that whatever value you pass
will be returned from the preceding *setjmp() you did...  When you first do the
*setjump(), it returns 0; then when you *longjmp() to that saved context, it returns
the value you pass to *longjmp()...  In this way, you can have multiple jump points,
and differing behavior based on that *setjump() return value...

Offline

#4 2007-08-23 09:18 AM

zhn636
Member
Registered: 2007-04-24
Posts: 146

Re: setjmp() and longjmp()

why we say setjmp()and longjmp() are horrible and ugly?what are their disvantages when we use them ? and how we can avoid use them? can you explain to me  ?thanks

Offline

#5 2007-08-23 01:23 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: setjmp() and longjmp()

Offline

  • Index
  • » C
  • » setjmp() and longjmp()

Board footer

Powered by FluxBB