Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commenting C code, header and source files [closed]

I'm looking for a "best practice" to document my C code. Like in any project I have some header files ".h" and the respective source file ".c"

In the header file what kind of comment you put in? And in source files? The question arise up because since I commented well my header files, the c files looks like a mess.

What's your best practices in keeping the code well commented?

like image 881
pygabriel Avatar asked Apr 07 '10 11:04

pygabriel


3 Answers

The header is meant for users of the code. So in there I document the interface: how to use it, preconditions and postconditions, etcetera.

The .c file is for maintainers. In there, I document the implementation: how things work internally, and why they work that way.

like image 186
Thomas Avatar answered Nov 12 '22 20:11

Thomas


I suggest adopting the conventions imposed by a tool like Doxygen. Then instead of just code comments, you can also generate HTML/PDF/Latex etc documentation and its gives you good conventions.

Agree with Thomas about the cpp files

like image 34
Hannes de Jager Avatar answered Nov 12 '22 20:11

Hannes de Jager


If this is a personal project I'd suggest there are plenty of coding standards out there you could adopt (almost all include sections on how to lay out comments).

If not, I would imagine your company / teaam / project already has something in place so use that.

like image 1
Jon Cage Avatar answered Nov 12 '22 20:11

Jon Cage