#pragma leaves

Description

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

Syntax

Read syntax diagramSkip visual syntax diagram                         .-,--------.
                         V          |
>>-#--pragma--leaves--(----function-+--)-----------------------><

Notes

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.

Example

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