Manpages

NOM

assert - Terminer le programme en cas d’échec d’un test

SYNOPSIS

#include <assert.h>

void assert(scalar expression);

DESCRIPTION

This macro can help programmers find bugs in their programs, or handle exceptional cases via a crash that will produce limited debugging output.

If expression is false (i.e., compares equal to zero), assert() prints an error message to standard error and terminates the program by calling abort(3). The error message includes the name of the file and function containing the assert() call, the source code line number of the call, and the text of the argument; something like:

prog: some_file.c:16: some_func: Assertion ’val == 0’ failed.

If the macro NDEBUG is defined at the moment <assert.h> was last included, the macro assert() generates no code, and hence does nothing at all. It is not recommended to define NDEBUG if using assert() to detect error conditions since the software may behave non-deterministically.

VALEUR RENVOYÉE

Aucune valeur n’est renvoyée.

ATTRIBUTS

Pour une explication des termes utilisés dans cette section, consulter attributes(7).

CONFORMITÉ

POSIX.1-2001, POSIX.1-2008, C89, C99. In C89, expression is required to be of type int and undefined behavior results if it is not, but in C99 it may have any scalar type.

BOGUES

assert() étant implémentée comme une macro, si l’expression testée a des effets de bord, le comportement du programme différera suivant l’existence de NDEBUG. Cela peut induire des « Heisenbugs » (N.d.T : bogue qui disparaît ou se modifie quand on essaye de le localiser) qui disparaissent lors du débogage.

VOIR AUSSI

abort(3), assert_perror(3), exit(3)

COLOPHON

Cette page fait partie de la publication 5.07 du projet man-pages Linux. Une description du projet et des instructions pour signaler des anomalies et la dernière version de cette page, peuvent être trouvées à l’adresse https://www.kernel.org/doc/man-pages/.

TRADUCTION

La traduction française de cette page de manuel a été créée par Christophe Blaess <https://www.blaess.fr/christophe/>;, Stéphan Rafin <stephan.rafin [AT] laposte.net>, Thierry Vignaud <tvignaud [AT] mandriva.com>, François Micaux, Alain Portal <aportal [AT] univ-montp2.fr>, Jean-Philippe Guérard <fevrier [AT] tigreraye.org>, Jean-Luc Coulon (f5ibh) <jean-luc.coulon [AT] wanadoo.fr>, Julien Cristau <jcristau [AT] debian.org>, Thomas Huriaux <thomas.huriaux [AT] gmail.com>, Nicolas François <nicolas.francois [AT] centraliens.net>, Florentin Duneau <fduneau [AT] gmail.com>, Simon Paillard <simon.paillard [AT] resel.fr>, Denis Barbier <barbier [AT] debian.org> et David Prévot <david [AT] tilapin.org>

Cette traduction est une documentation libre ; veuillez vous reporter à la GNU General Public License version 3 concernant les conditions de copie et de distribution. Il n’y a aucune RESPONSABILITÉ LÉGALE.

Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à <debian-l10n-french [AT] lists.org>.