How to automatically generate function headers for .h file in Clion?

11,289

Solution 1

Maybe it's a little late (about 4 years), but here's the best way i've found (for a c file):

cut and paste the contents of the .c in the .h file, and for each function, put the cursor on it's name and press Alt+Enter, and choose "Split function into declaration and definition".

this will keep the declaration in the .h file while moving the implementation to the .c file.

hope it helps someone.

Solution 2

This only works for C++, but after you've written a function definition in a cpp file, eg:

void MyClass::myNewFn() { ... }

you can do Alt-Enter on myNewFn and select 'Create new function myNewFn()'. This will add a declaration of MyClass in the header file.

Share:
11,289

Related videos on Youtube

Ali Alavi
Author by

Ali Alavi

Interests: Algorithms and Data Structure, IoT, Machine Learning, Programming Languages, Software Engineering

Updated on December 18, 2021

Comments

  • Ali Alavi
    Ali Alavi over 2 years

    When writing a library in C, I usually end up implementing functions before defining them in the corresponding header file. As copying function header's in the header file is a repetitive task, I was wondering if I can automatically generate function headers (or even better, the full header file) in CLion?

  • Frode Akselsen
    Frode Akselsen about 7 years
    he is asking about c