#pragma leaves


The #pragma leaves directive takes a function name and specifies that the function never returns to the instruction after the call.


Read syntax diagramSkip visual syntax diagram                         .-,--------.
                         V          |


This pragma tells the compiler that function never returns to the caller.

The advantage of the pragma is that it allows the compiler to ignore any code that exists after function, in turn, the optimizer can generate more efficient code. This pragma is commonly used for custom error-handling functions, in which programs can be terminated if a certain error is encountered. Some functions which also behave similarily are exit, longjmp, and terminate.


#pragma leaves(handle_error_and_quit)
void test_value(int value)
	if (value == ERROR_VALUE)
		TryAgain();	// optimizer ignores this because
				// never returns to execute it