[Overview]

Tags for C Headers

 

Conventions

Tags, depending on type, can introduce either one or two fields of information:

In the tables below, the "Fields" column indicates the number of textual fields each type of tag takes.

The tags highlighted in RED below are required.

 

Tags Common to All API Types

The @abstract, @updated, and @discussion tags can be used within any of the type-specific tags below. For example,:

/*!
  @enum Beverage Categories
  @abstract Constants to group beverage types.
  @discussion These constants (such as kSoda, kBeer, etc.) can be used...
  @updated 2003-04-15
*/

They are not required within any HeaderDoc comment, but can improve the formatting of the HTML output, and can help automate the importation of comments into the Inside Mac documentation database.

 

Class Tags

Tag
Identifies
Fields
@class The name of the class.
1

Example:

/*! 
  @class IOFireWireDeviceInterface_t
*/
  typedef struct IOFireWireDeviceInterface_t
{
	IUNKNOWN_C_GUTS ;
.
.
.
}

The @class tag causes the typedef struct that follows the headerdoc comment to be treated as a class. This is commonly used for COM interfaces, but is also a frequently-used technique in kernel programming.

You should mark up any C pseudoclasses in the same way as you would mark up a C++ class. Apart from the unusual form of function declarations (in the form of function pointers), the resulting output should be similar to that of a C++ class.

 

Function Group Tags

Tag
Identifies
Fields
@functiongroup The name of the function group.
1

Example:

/*! 
  @functiongroup Core Functions
*/

Function groups are not required, but they allow you to organize a large number of functions into near groupings. The @functiongroup tag remains in effect until the next @functiongroup tag.

If you need to put functions in different parts of the header into the same group, simply give them the same name (with the same capitalization, punctuation, spacing, etc.), and it will merge the two function groups into one.

Note that functions encountered before the first @functiongroup are considered part of the "empty" group. These functions will be listed before any grouped functions.

 

Function Tags

Tag
Identifies
Fields
@function The name of the function.
1
@param Each of the function's parameters.
2
@result The return value of the function. Don't include if the return value is void or OSERR
1

Example:

/*! 
  @function ConstructBLT
  @discussion Creates a Sandwich structure from the supplied arguments.
  @param b Top ingredient, typically protein-rich.
  @param l Middle ingredient.
  @param t Bottom ingredient, controls tartness.
  @param mayo A flag controlling addition of condiment. Use YES for condiment,
              HOLDTHE otherwise.
  @result A pointer to a Sandwich structure. Caller is responsible for 
          disposing of this structure.
*/
Sandwich *ConstructBLT(Ingredient b, Ingredient l, Ingredient t, Boolean mayo);

Struct and Union Tags

Tag
Identifies
Fields
@struct / @union The name of the structure or union. (Also known as the struct or union's tag.)
1
@field A field in the structure.
2

Example:

/*!
  @struct TableOrigin
  @discussion Locates lower-left corner of table in screen coordinates.
  @field x Point on horizontal axis.
  @field y Point on vertical axis
*/
struct TableOrigin {
    int x;
    int y;
}

Enum Tags

Tag
Identifies
Fields
@enum The name of the enumeration. This is the enum's tag, if it has one. Otherwise, supply a name you want to have the constants grouped under in the documentation.
1
@constant A constant within the enumeration.
2

Example:

/*!
  @enum Beverage Categories
  @discussion Categorizes beverages into groups of similar types.
  @constant kSoda Sweet, carbonated, non-alcoholic beverages.
  @constant kBeer Light, grain-based, alcoholic beverages.
  @constant kMilk Dairy beverages.
  @constant kWater Unflavored, non-sweet, non-caloric, non-alcoholic beverages.
*/
enum {
  kSoda = (1 << 6),
  kBeer = (1 << 7),
  kMilk = (1 << 8),
  kWater = (1 << 9)
}

Typedef Tags

Tag
Identifies
Fields
@typedef The name of the defined type.
1
various The tags that can appear after a "@typedef" tag depend on the definition of the new type.

@field for typedef'd structs
@constant for typedef'd enumerations
@param for simple typedef'd function pointers
@callback, @param, @result for typedef'd structs containing function pointers

Example 1 - Typedef for a simple struct:

/*!
    @typedef TypedefdSimpleStruct
    @abstract Abstract for this API.
    @discussion Discussion that applies to the entire typedef'd simple struct.
    @field firstField Description of first field
    @field secondField Description of second field
*/

typedef struct _structTag {
    short firstField;
    unsigned long secondField
} TypedefdSimpleStruct;

 

Example 2 - Typedef for an enumeration:

/*!
    @typedef TypedefdEnum
    @abstract Abstract for this API.
    @discussion Discussion that applies to the entire typedef'd enum.
    @constant kCFCompareLessThan Description of first constant.
    @constant kCFCompareEqualTo Description of second constant.
    @constant kCFCompareGreaterThan Description of third constant.
*/
typedef enum {
    kCFCompareLessThan = -1,
    kCFCompareEqualTo = 0,
    kCFCompareGreaterThan = 1
} TypedefdEnum;

 

Example 3 - Typedef for a simple function pointer:

/*!
    @typedef simpleCallback
    @abstract Abstract for this API.
    @discussion Discussion that applies to the entire callback.
    @param inFirstParameter Description of the callback's first parameter.
    @param outSecondParameter Description of the callback's second parameter.
    @result Returns what it can when it is possible to do so.
*/
typedef long (*simpleCallback)(short inFirstParameter, unsigned long long *outSecondParameter);

 

Example 4 - Typedef for a struct containing function pointers:

/*! @typedef TypedefdStructWithCallbacks
    @abstract Abstract for this API.
    @discussion Defines the basic interface for Command DescriptorBlock (CDB) commands.
        
    @field firstField Description of first field.
    
    @callback setPointers Specifies the location of the data buffer. The setPointers function has the following parameters:
    @param cmd A pointer to the CDB command interface.
    @param sgList A pointer to a scatter/gather list.
    @result An IOReturn structure which returns the return value in the structure returned.  

    @field lastField Description of the struct's last field.
*/
typedef struct _someTag {
    short firstField;
    IOReturn (*setPointers)(void *cmd, IOVirtualRange *sgList);
    unsigned long lastField
} TypedefdStructWithCallbacks;

 

const Tags

Tag
Identifies
Fields
@const Name of the constant.
1

Example:

  /*!
    @const kCFTypeArrayCallBacks
    @discussion Predefined CFArrayCallBacks structure containing a set of callbacks appropriate...
  */
  const CFArrayCallBacks kCFTypeArrayCallBacks;

 

#define Tags

Tag
Identifies
Fields
@defined Name of the constant.
1

Example:

  /*!
    @defined TRUE
    @discussion Defines the boolean true value.
  */
  #define TRUE 1
  

 


For more usage examples, see the ExampleHeaders folder that accompanies the HeaderDoc distribution.