Skip to contentSkip to conversation

help for using setjmp and longjmp functions

DISCUSSION Jagadeesh Bhaskar P 1 participant 1 message Dec 20, 2004

lore
Share & tools
lore
#0 lore raw

Hi,
I tried writing a simple program to findout usage of setjmp and
longjmp() functions. The program ran in an infinite loop showing some warnings. What is the problem? Can someone help me depicting the behaviour of the setjmp and longjmp functions

/******** beginning of code *************/

#include <setjmp.h>
jmp_buf jmpbuffer;

void bar(void)

{
	printf("inside bar\n");
	longjmp(jmpbuffer, 1);
}

void foo(void)

{
	printf("before calling bar()\n");
	bar();
	printf("after calling bar()\n");
}
int
main(void)
{
	printf("before calling foo()\n");
	if(setjmp(jmpbuffer)!=0)
		perror("error setting");
	foo();
	printf("after foo()\n");

	return 0;
}

/**************** end of code ***********/

Hoping for help

TIA..

Signature · 3 lines
With regards,

Jagadeesh Bhaskar P