1

Accordingly to Doxygen's manual, there are some standards to correctly comment a program written in C. Unfortunately the way of documenting a program doesn't seem to be well standardized (i.e. GNU Coding Standards).

If I agree that the most common header for a function is:

/** * Brief description. * * @param a first parameter * @return if any return value * * Detailed description **/ 

Unfortunately this solution is quite tiresome when I need to quickly comment a block of code with /* ... */. It is the reason why I prefer using // which doesn't interact with /*..*/. So what is the most advisable way of writing function comment header? Also most of the today's standards are based on a legacy C89 standards.

Second point of my question concerns the section comments. I often have in different sections in my code that I would like to clearly separate. For example:

/** * @file foo.c * * StackOverflow Example **/ /************************************************************* * Includes ************************************************************/ #include <stdio.h> ... /************************************************************* * Prototypes ************************************************************/ void foo(); void bar(); ... 

Is there any C programming standard largely used that precisely define how to write such separators based on a study (less cumbersome, less tiring for the eyes, most used by the community, ...)?

6
  • As far as i know how to seperate sections is not define you can do what erver you want! Commented Nov 6, 2014 at 13:49
  • 1
    @Rizier123 This is also what I think but in the case of programming I hate when I can do what ever I want to do. If there is any standards I prefer to stick to it. Commented Nov 6, 2014 at 13:53
  • then set your own standards ! (Make your own coding guidelines) Commented Nov 6, 2014 at 13:54
  • 1
    @Rizier123 That's what everybody does :( Commented Nov 6, 2014 at 13:55
  • 2
    If you're using doxygen, why not go all the way and keep everything compatible with it? For instance, it has \section and \subsection which can also function as separators. If you find its syntax tiresome, you could set your editor to spit out snippets with a few keystrokes. Commented Nov 6, 2014 at 14:09

1 Answer 1

3

I think it comes down to preference and readability.

For example I like to use the following:

/*---------------------- | Function | Author: | Dependencies: ----------------------*/ /*---------------------- | Section -----------------------*/ //Comments in sections 

I use this in conjunction with the following rules for readability.

  • 2 line returns before a section heading/Comment
  • 1 line return after a section heading/Comment

The easiest way I have found to block quote is to highlight the code and then to use the keyboard short-cut Ctrl + Shift + / to comment out that block. Works in most editors.

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.