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
In the editor, select the expression you want to replace with a macro call.
Press Shortcut is missing or select
from the main or context menu.If there are several expressions available for extracting, select the required one from the list that opens and press Enter.
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.
Select a name for the macro from the list of suggestions or type a new one.
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: 14 September 2023