CLion 2023.3 Help

Extract define

The Extract Define refactoring method defines the selected set of tokens as macro using #define directive and replaces the set of tokens with macro call in the code.

Extract #define

  1. In the editor, select the expression you want to replace with a macro call.

  2. Press Ctrl+Alt+D or select Refactor | Extract/Introduce | Define from the main or context menu.

  3. If there are several expressions available for extracting, select the required one from the list that opens and press Enter.

  4. If more than one occurrence of the selected expression is found, CLion will suggest replacing all the occurrences or just the selected one. Select the desired option from the list that opens.

    Extract define multiple occurrences
  5. Select a name for the macro from the list of suggestions or type a new one.

    Set the define name

Code example

Before

After

int main() { int maxValue = 65536 * 65536; return 0; }
#define MAX 65536 int main() { int maxValue = MAX * MAX; return 0; }
Last modified: 11 February 2024