coding style - C function headers location: .h or .c? -
this question has answer here:
- where document functions in c? 11 answers
suppose have function (external considered here) int foo(int a, char *b), there header goes documenting function does, each parameter , return value does, etc. it'll in doxygen format too. habit such header should go .h files because that's interface defined , reader should have information in place. lot of people keep such headers in c file actual implimentation goes. i've seen in linux kernel code also. wrong? prefer?
although header files can used in way, mechanism enable external linkage.
you design api meant external consumption, , put required consume api (constants, types, prototypes) in header file(s).
all other stuff, part of implementation, , doesn't need seen external users, can go in source files (if usage localized 1 file), or private headers can shared between multiple files. latter example of header files enabling external linkage, internal consumption.
Comments
Post a Comment