[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


setjmp

Save the processor state for longjmp().

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <setjmp.h>
int setjmp(jmp_buf env);
Parameters:

Parameters for this facility are:

env  
jmp_buf  
The current processor state  

Remarks:

The setjmp() function saves the calling environment-data and address registers, the stack pointer, and the program counter-in the env argument. The argument must be initialized by setjmp() before being passed as an argument to longjmp().


WARNING!

The setjmp function is redefined when AltiVec support is enabled. The programmer must ensure that both the "from" compilation unit and "to" compilation unit have AltiVec enabled. Failure to do so will create an undesired result.
Return:

When it is first called, setjmp() saves the processor state and returns 0. When longjmp() is called program execution jumps to the setjmp() that saved the processor state in env. When activated through a call to longjmp(), setjmp() returns longjmp()'s val argument.

See Also:

"longjmp"

"signal"

"abort"

setjmp() example:
#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>

// Let main() and doerr() both have 
// access to global env
volatile jmp_buf env;

void doerr(void);
int main(void)
{

	int i, j, k;

	printf("Enter 3 integers that total less than 100.\n");
	printf("A zero sum will quit.\n\n");

	// If the total of entered numbers is not less than 100,
	// program execution is restarted from this point.

	if (setjmp(env) != 0)
		printf("Try again, please.\n");

	do {
		scanf("%d %d %d", &i, &j, &k);
		if ( (i + j + k) == 0)
			exit(0);		// quit program
		printf("%d + %d + %d = %d\n\n", i, j, k, i+j+k);
		if ( (i + j + k) >= 100)
			doerr(); 	// error!
	} while (1);		// loop forever

	return 0;
}

void doerr(void)		// this is the error handler
{
	printf("The total is >= 100!\n");
	longjmp(env, 1); 
}
Output:

Enter 3 integers that total less than 100.
A zero sum will quit.

10 20 30
10 + 20 + 30 = 60

-4 5 1000
-4 + 5 + 1000 = 1001

The total is >= 100!
Try again, please.
0 0 0


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000