30

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?

Ali Alavi
  • 2,367
  • 2
  • 18
  • 22

2 Answers2

17

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.

prophet-five
  • 509
  • 3
  • 14
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.

jtbr
  • 1,149
  • 13
  • 13