Skip to main content
added 118 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

## is the concatenation operator in macros. It joins two macros or pieces of text together when expanded.

#define _SET_INPUT(IO) do {DIO ##  IO ## _DDR &= ~MASK(DIO ## IO ## _PIN); } while (0)

_SET_INPUT(3);

woukd expand, if IO were 3, to:

do {DIO3_DDR &= ~MASK(DIO3_PIN); } while (0);

You can read more about how it works here: https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

## is the concatenation operator in macros. It joins two macros together when expanded.

DIO ## IO ## _DDR

woukd expand, if IO were 3, to

DIO3_DDR

## is the concatenation operator in macros. It joins two macros or pieces of text together when expanded.

#define _SET_INPUT(IO) do {DIO ##  IO ## _DDR &= ~MASK(DIO ## IO ## _PIN); } while (0)

_SET_INPUT(3);

woukd expand to:

do {DIO3_DDR &= ~MASK(DIO3_PIN); } while (0);

You can read more about how it works here: https://gcc.gnu.org/onlinedocs/cpp/Concatenation.html

Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

## is the concatenation operator in macros. It joins two macros together when expanded.

DIO ## IO ## _DDR

woukd expand, if IO were 3, to

DIO3_DDR