oled 1.0
OLED Graphics Control Library
Loading...
Searching...
No Matches
STRING_macros.h File Reference

Helper macros for stringification in C preprocessor. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _STR2(x)
 Converts a macro argument into a string literal (internal helper).
#define _STR(x)
 Converts a macro argument into a string literal (with expansion).

Detailed Description

Helper macros for stringification in C preprocessor.

This header file provides macros for converting tokens or macro values into string literals using the C preprocessor.

It contains two essential macros:

  • _STR2(x) : Performs direct stringization of a token without expansion.
  • _STR(x) : Expands a macro argument before converting it into a string literal.

These utilities are commonly used when embedding macro constants into message strings, compiler attributes, or debug output.

Note
_STR() should be preferred over _STR2() since it ensures proper expansion of macro arguments before stringization.
Author
g.raf
Date
2025-09-18
Version
1.0 Release
Note
This file is part of a larger project and subject to the license specified in the repository. For updates and the complete revision history, see the GitHub repository.
See also
https://github.com/0x007e/avr-common "AVR ATmega GitHub Repository"

Macro Definition Documentation

◆ _STR

#define _STR ( x)
Value:
#define _STR2(x)
Converts a macro argument into a string literal (internal helper).
Definition STRING_macros.h:44

Converts a macro argument into a string literal (with expansion).

This macro first expands its argument x (if it is another macro), and then calls _STR2(x) to convert it into a string literal.

For example:

#define VALUE 42
const char *str1 = _STR(VALUE); // expands to "42"
const char *str2 = _STR(TEXT); // expands to "TEXT"
#define _STR(x)
Converts a macro argument into a string literal (with expansion).
Definition STRING_macros.h:68
Parameters
xToken or macro to be expanded and converted into a string literal.
Returns
A string literal representing the expanded input.
Note
This macro is the preferred way to stringify macros, since it guarantees full expansion before stringization.

◆ _STR2

#define _STR2 ( x)
Value:
#x

Converts a macro argument into a string literal (internal helper).

This macro takes a single argument x and applies the preprocessor stringization operator (#), converting the token into a string literal. It is usually not used directly, but rather invoked via the higher-level macro _STR(), which ensures proper macro expansion before stringization.

Parameters
xToken to be converted into a string literal.
Returns
A string literal representing the input token.
Note
This macro does not expand other macros passed as x before stringizing. Use _STR() for full expansion.