linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* help for using setjmp and longjmp functions
@ 2004-12-20  7:08 Jagadeesh Bhaskar P
  0 siblings, 0 replies; 2+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-12-20  7:08 UTC (permalink / raw)
  To: Linux C Programming

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..

-- 
With regards,

Jagadeesh Bhaskar P


^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: help for using setjmp and longjmp functions
       [not found] <50C05B7AA7D6924FB5E384EF14BC647B495EE4@inba1mx2.corp.emc.com>
@ 2004-12-20  7:54 ` Jagadeesh Bhaskar P
  0 siblings, 0 replies; 2+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-12-20  7:54 UTC (permalink / raw)
  To: Honnavalli_Sreevathsa; +Cc: Linux C Programming

Yes I got it.....Thanks
On Mon, 2004-12-20 at 13:15, Honnavalli_Sreevathsa@emc.com wrote:
> Try this modified code. Hope its self explanatory. (This program does not
> demonstrate the best usage of setjmp/longjmp anyway. But ok for
> understanding the usage)
> 
> 
> #include <setjmp.h>
> jmp_buf jmpbuffer;
> 
> void bar(void)
> {
>         sleep(1);
>         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))
>         {
>                 printf("returned back from longjmp\n");
>                 goto done;
>         }
>         foo();
> 
> done:
>         printf("after foo()\n");
>         printf("\n-------------------------------------\n");
> 
>         return 0;
> }
> 
> 
> 
> 
> 
> > -----Original Message-----
> > From: linux-c-programming-owner@vger.kernel.org 
> > [mailto:linux-c-programming-owner@vger.kernel.org] On Behalf 
> > Of Jagadeesh Bhaskar P
> > Sent: Monday, December 20, 2004 12:38 PM
> > To: Linux C Programming
> > Subject: help for using setjmp and longjmp functions
> > 
> > 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..
> > 
> > -- 
> > With regards,
> > 
> > Jagadeesh Bhaskar P
> > 
> > -
> > To unsubscribe from this list: send the line "unsubscribe 
> > linux-c-programming" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
-- 
Jagadeesh Bhaskar P <jbhaskar@hclinsys.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-12-20  7:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-20  7:08 help for using setjmp and longjmp functions Jagadeesh Bhaskar P
     [not found] <50C05B7AA7D6924FB5E384EF14BC647B495EE4@inba1mx2.corp.emc.com>
2004-12-20  7:54 ` Jagadeesh Bhaskar P

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).