(extrait du fichier fork.c
du noyau Linux)
/* * Check if we are over our maximum process limit, but be sure to * exclude root. This is needed to make it possible for login and * friends to set the per-user process limit to something lower * than the amount of processes root is running. -- Rik */ if (atomic_read(&p->user->processes) >= p->rlim[RLIMIT_NPROC].rlim_cur && !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) goto bad_fork_free;
(extrait de perlbug.PL
dans la distribution standard de Perl)
# a strange way to check whether any significant editing # have been done: check whether any new non-empty lines # have been added. Yes, the below code ignores *any* space # in *any* line. while () { s/\s+//g; $unseen++ if $_ ne '' and not exists $REP{$_}; }
(extrait de MediaWiki, le logiciel utilisé par Wikipedia, une encyclopédie collaborative en ligne)
/* * Scan forwards to find beginning of another run of changes. * Also keep track of the corresponding point in the other file. * * Throughout this code, $i and $j are adjusted together so that * the first $i elements of $changed and the first $j elements * of $other_changed both contain the same number of zeros * (unchanged lines). * Furthermore, $j is always kept so that $j == $other_len or * $other_changed[$j] == false. */ while ($j < $other_len && $other_changed[$j]) $j++;
Des outils comme doxygen, javadoc ou rdoc permettent de structurer les commentaires présents dans le code et de générer une documentation complète. Celle-ci est la plupart du temps destinée à un programmeur désirant développer avec une bibliothèque, mais il est tout à fait possible d’utiliser cette méthode pour écrire la documentation destinée à l’utilisateur final.
/** * Registers the text to display in a tool tip. The text * displays when the cursor lingers over the component. * * @param text the string to display. If the text is null, * the tool tip is turned off for this component. */ public void setToolTipText(String text) {
(un extrait de la documentation javadoc de Sun Microsystems ; le commentaire est dans un format compréhensible par le processeur javadoc)
On utilise souvent les commentaires pour cacher rapidement des portions de code au compilateur ou à l’interpréteur, par exemple pour tester des implémentations alternatives, ou pour désactiver temporairement des fonctionnalités.
Cette désactivation est la plus facile à effectuer lorsque le langage permet des commentaires par blocs. Cependant, dans le cas où la portion de code à cacher contient déjà des commentaires, la syntaxe du langage ne permet pas toujours de simplement d’imbriquer ces commentaires. Certains langages fournissent un niveau supérieur de commentaires pour pallier cela :
#if 0
code; //commentaire
encore du code; /* commentaire */
#endif
]]>