Dave's Brain

Browse - programming tips - compiled comment

Date: 2005Jun1
Language: C/C++

Q.  Sometimes comments that refer to code get out of date.
    Is there a way to avoid this without adding to the size of the program?

A.  Compile your comments in an inline function but never call the function.
    A good use of this trick to document an API in the header file.
    Here's an example header file:

int ExplodeBomb(const int megatons_requested);

inline void ExampleUse()
{
	int	megatons_requested = 10;
	int	megatons_used;

	// Here is how you might use the ExplodeBomb function:

	megatons_used = ExplodeBomb(megatons_requested);
}

// If the function is renamed or the number/type of parameters
// changes the ExampleUse() function won't compile and you can fix it.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.