Advertisement

How to document single header files properly (Intellisense)

Started by June 29, 2018 10:44 AM
4 comments, last by Finalspace 6 years, 2 months ago

I have written a couple of single header file libraries and all are fully documented using doxygen style in the header part.

As soon as i start using the functions in a project, no documentation will show up in intellisense - regardless of the documentation style (XML style does not work either).

However the implementation does not have any documentations whatsoever and i dont want to duplicate the same documentation block over and over again.

Example:


#ifndef MYLIB_H
#define MYLIB_H
/**
  * \brief Returns a length squared by the given two parameters
  * \param x X-position
  * \param x Y-position
  * \return Distance by X and Y
  */
int mylibGetLengthSq(float x, float y);
#endif // MYLIB_H

#if defined(MYLIB_IMPLEMENTATION) && !defined(MYLIB_IMPLEMENTED)
#define MYLIB_IMPLEMENTED
float mylibGetLengthSq(float x, float y) {
  float result = x * x + y * y;
  return(result);
}
#endif // MYLIB_IMPLEMENTATION

How do i change that, so that documentation are used from the header file only or ignoring the not defined implementation documentation. Is that possible?

Of course if i include the implementation in a separated C/C++ file, it works correctly - but i want to prevent that.

Is there any way to mark a function implementation as (Never ever try to parse documentation from here)...??

I would personally not bother with the single-header file implementation and instead move the implementation into .cpp files.  You will end up with cleaner looking code and avoid your issue altogether.

Indie Game Dev

Advertisement

Yeah 2-file is preferable to 1-file:)

However, if you want to hide code from intellisense you can use #ifndef __INTELLISENSE__ / #endif

I always document the implementation rather than the declaration, since that keeps the documentation close to the code, making it easier to update the docs if you change the code.

Since you have one file anyway, wouldn't that work?

On 7/1/2018 at 6:56 AM, Alberth said:

I always document the implementation rather than the declaration, since that keeps the documentation close to the code, making it easier to update the docs if you change the code.

Since you have one file anyway, wouldn't that work?

I have more than one implementation for a function, so i dont want to go this route ?

And each implementation should always do exactly for what the function is intented/named, so there are no difference in documentation for each implementation.

On 6/30/2018 at 12:46 PM, Hodgman said:

Yeah 2-file is preferable to 1-file:)

However, if you want to hide code from intellisense you can use #ifndef __INTELLISENSE__ / #endif

Oh great, that looks promising so i will try that macro ;)

Regarding two files policy: I agree for medium to large projecs - but for smaller ones i like to have just one translation unit only.

*Edit: Awesome the intellisense macro work like a charm ;) Thanks again!

This topic is closed to new replies.

Advertisement