BETA Try the new lesson view
Code

Doxygen comments

daytime.h already has contracts, but in free form. Doxygen is a convention for writing such comments so that tools understand them too: CLion shows them when you hover over a function, and the doxygen program can generate documentation from them. From this topic on every .h of yours is written this way.

What it looks like

A Doxygen comment starts with /** (two stars) and goes before the declaration:

/**
 * @brief Turns a time into minutes since midnight.
 * @param hour the hour
 * @param min the minutes
 * @pre is_time(hour, min)
 * @return 0 to MINUTES_PER_DAY - 1.
 */
int to_minutes(int hour, int min);
tag what
@file the file name, at the top of the file
@brief one sentence: what it does
@param every parameter: its name and meaning
@return what it returns (not written for a void function)
@pre the precondition: what the assert checks

A constant needs only one line: /** How many minutes a day has. */.

Change daytime.h

At the top of the file, @file and @brief about the whole module. Rewrite every /* ... */ comment as /** ... */ with tags. The contracts don't change, only the form: "Before:" becomes @pre, "After:" becomes @return.

CLion helps: type /** above a declaration and press Enter, and CLion generates a skeleton with @param and @return for every parameter.

See what the user sees

Open main.c, hover over read_time, or put the cursor on it and press Ctrl+Q. The pop-up shows your @brief and @return. Whoever uses the module no longer needs to open daytime.c.

Build and run: comments don't change the program.

Commit: Add Doxygen comments.