CLion 2021.2 Help

Extract typedef

The Extract Typedef refactoring changes the selected declaration of a type to a typedef definition. You can apply Extract Typedef when actual declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another, or just to make code presentation more clear and readable.

Example

Before

After

int main() { void f(int); void (*pf1)(int) = &f; return 0; }
typedef void (*pFunction)(int); int main() { void f(int); pFunction pf1 = &f; return 0; }

Extract typedef in-place

  1. In the editor, select the type declaration to be re-declared. You can do that yourself or use the smart expression selection feature to let CLion help you. So, do one of the following:

    • Highlight the token. Then choose Refactor | Extract | Extract Typedef from the main or context menu.

    • Alternatively, press Ctrl+Alt+K.

  2. If more than one occurrence of the selected expression is found, select Replace this occurrence only or Replace all occurrences in the Multiple occurrences found popup menu.

    Cl extract type def multiple occurrence

    To select the required option, just click it. Alternatively, use the Up and Down arrow keys to navigate to the option of interest, and press Enter to select it.

    • In the Typedef popup menu, select the type name by clicking the required name. Alternatively, use the Up and Down arrow keys to navigate to the name of interest, and then press Enter to select it.

  3. Select Put to header checkbox if you want to move created typedef definition to the header file.

  4. Specify the name of the new type. Do one of the following:

    • Select one of the suggested names from the list. To do that, double-click the suitable name. Alternatively, use the Up and Down arrow keys to navigate to the name of interest, and Enter to select it.

    • Edit the name by typing. The name is shown in the box with red borders and changes as you type. When finished, press Enter.

Last modified: 26 August 2021