#pragma leaves

Category

Optimization and tuning

Purpose

Informs the compiler that a named function never returns to the instruction following a call to that function.

By informing the compiler that it can ignore any code after the function, the directive allows for additional opportunities for optimization.

This pragma is commonly used for custom error-handling functions, in which programs can be terminated if a certain error is encountered.

Note: The compiler automatically inserts #pragma leaves directives for calls to the longjmp family of functions (longjmp, _longjmp, siglongjmp, and _siglongjmp) when you include the setjmp.h header.

Syntax

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

Parameters

function_name
The name of the function that does not return to the instruction following the call to it.

Defaults

Not applicable.

Examples

#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
	}
}

Related information