BDE 4.14.0 Production release
Loading...
Searching...
No Matches

Macros

#define BSLA_USED
 

Detailed Description

Outline

Purpose

Provide a macro to prevent elision of unused entities.

Macros

See also
bsla_annotations

Description

This component provides a preprocessor macro that will guarantee the emission of a local function, type, or variable whether it is used or not.

Macro Reference

BSLA_USED: This annotation indicates that the so-annotated function, variable, or type must be emitted even if it appears that it is not referenced.

BSLA_USED_IS_ACTIVE: The macro BSLA_USED_IS_ACTIVE is defined if BSLA_USED expands to something with the desired effect; otherwise BSLA_USED_IS_ACTIVE is not defined and BSLA_USED expands to nothing.

Usage

This section illustrates intended use of this component.

Example 1: Unused Variables

First, we declare two unused static variables, one marked BSLA_UNUSED and the other marked BSLA_USED:

static
int usage_UNUSED_variable_no_warning BSLA_UNUSED;
static
int usage_USED_variable_no_warning BSLA_USED;
#define BSLA_UNUSED
Definition bsla_unused.h:237
#define BSLA_USED
Definition bsla_used.h:151

Finally, if we compile with clang and go into the debugger and stop in main, which is in the same file and from which both variables are visible, we observe that the variable marked BSLA_UNUSED cannot be accessed, but the variable marked BSLA_USED can.

Example 2: Unused Functions

First, declare two unused static functions, one marked BSLA_UNUSED and one marked BSLA_USED:

/// Print the specified 'woof'.
static
void usage_UNUSED_function_no_warning(int woof) BSLA_UNUSED;
static
void usage_UNUSED_function_no_warning(int woof)
{
printf("%d\n", woof);
}
/// Print the specified 'woof'.
static
void usage_USED_function_no_warning(int woof) BSLA_USED;
static
void usage_USED_function_no_warning(int woof)
{
printf("%d\n", woof);
}

Finally, if we compile with clang and go into the debugger, we find that we can put a breakpoint in the function marked BSLA_USED, but not in the function marked BSLA_UNUSED.

Macro Definition Documentation

◆ BSLA_USED

#define BSLA_USED