]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/assert.h
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / Include / assert.h
1 /** @file
2 Provides a definition of the assert macro.
3
4 This header file defines the assert macro and refers to the NDEBUG macro,
5 which is NOT defined in this file.
6
7 Unlike other header files, assert.h is designed to be included multiple
8 times, with potentially different behavior on each inclusion.
9
10 If the NDEBUG macro is defined at the point where assert.h
11 is included, the assert macro is defined so as to not produce code.
12 Otherwise, the assertion is tested and if the assertion is true a
13 diagnostic message of the form
14 "ASSERT <FileName>(<LineNumber>): <Description>\n" is produced.
15 A true assertion will also result in the application being terminated.
16
17 The behavior of the assert macro can be further modified by setting attributes
18 in the PcdDebugPropertyMask PCD entry when building the Application Toolkit.
19 If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of PcdDebugProperyMask is set
20 then CpuBreakpoint() is called. Otherwise, if the
21 DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
22 CpuDeadLoop() is called. If neither of these bits are set, then the
23 application will be terminated immediately after the message is printed to
24 the debug output device.
25
26 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
27 This program and the accompanying materials are licensed and made available under
28 the terms and conditions of the BSD License that accompanies this distribution.
29 The full text of the license may be found at
30 http://opensource.org/licenses/bsd-license.php.
31
32 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
33 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
34
35 **/
36 #include <sys/EfiCdefs.h>
37
38 #undef assert ///< Remove any existing definition for assert.
39
40 extern void
41 __assert(const char *func, const char *file, int line, const char *failedexpr);
42
43 /** The assert macro puts diagnostic tests into programs; it expands to a
44 void expression.
45
46 When it is executed, if expression (which shall have a scalar type) is
47 false (that is, compares equal to 0), the assert macro writes information
48 about the particular call that failed (including the text of the argument,
49 the name of the source file, the source line number, and the name of the
50 enclosing function - the latter are respectively the values of the
51 preprocessing macros __FILE__ and __LINE__ and of the identifier __func__)
52 on the standard error stream. It then calls the abort function.
53
54 If NDEBUG is not defined, Expression is evaluated. If Expression evaluates to FALSE, then
55 __assert is called passing in the source filename, source function, source line number,
56 and the Expression.
57
58 @param Expression Boolean expression.
59
60 @{
61 **/
62 #ifdef NDEBUG
63 #define assert(Expression) /* ignored */
64
65 #else
66 #define assert(Expression) ((Expression) ? (void)0 :\
67 __assert(__func__, __FILE__, __LINE__, #Expression) )
68 #endif
69 /// @}
70 /* END of file assert.h */