]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/assert.h
Fix GCC build errors.
[mirror_edk2.git] / StdLib / Include / assert.h
CommitLineData
2aa62f2b 1/** @file\r
681cc25c 2 Provides a definition of the assert macro used to insert diagnostic messages\r
3 into code.\r
2aa62f2b 4\r
5 This header file defines the assert macro and refers to the NDEBUG macro,\r
6 which is NOT defined in this file.\r
7\r
8 Unlike other header files, assert.h is designed to be included multiple\r
9 times, with potentially different behavior on each inclusion.\r
10\r
11 If the NDEBUG macro is defined at the point where assert.h\r
12 is included, the assert macro is defined so as to not produce code.\r
681cc25c 13 Otherwise, the assertion is tested and if the assertion is FALSE\r
14 (e.g. evaluates to 0) a diagnostic message of the form<BR>\r
15 "Assertion failed: (EXPR), file FILE, function FUNC, line LINE.\n"<BR>\r
16 is produced.\r
17 A FALSE evaluation will also result in the application being aborted.\r
2aa62f2b 18\r
681cc25c 19 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
20 This program and the accompanying materials are licensed and made available under\r
21 the terms and conditions of the BSD License that accompanies this distribution.\r
22 The full text of the license may be found at\r
23 http://opensource.org/licenses/bsd-license.\r
24\r
25 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
26 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
2aa62f2b 27**/\r
28#include <sys/EfiCdefs.h>\r
29\r
30#undef assert ///< Remove any existing definition for assert.\r
31\r
681cc25c 32/** Internal helper function for the assert macro.\r
33 The __assert function prints a diagnostic message then exits the\r
34 currently running application.\r
35\r
36 This function should NEVER be called directly.\r
37\r
38 Some pre-processors do not provide the __func__ identifier. When that is\r
39 the case, __func__ will be NULL. This function accounts for this and\r
40 will modify the diagnostic message appropriately.\r
41\r
42\r
43 @param[in] file The name of the file containing the assert.\r
44 @param[in] func The name of the function containing the assert.\r
45 @param[in] line The line number the assert is located on.\r
46 @param[in] failedexpr A literal representation of the assert's expression.\r
47\r
48 @return The __assert function will never return. It aborts the\r
49 current application and returns to the environment that\r
50 the application was launched from.\r
51**/\r
2aa62f2b 52extern void\r
681cc25c 53__assert(const char *file, const char *func, int line, const char *failedexpr);\r
2aa62f2b 54\r
55/** The assert macro puts diagnostic tests into programs; it expands to a\r
56 void expression.\r
57\r
681cc25c 58 When it is executed, if expression (which must have a scalar type) is\r
59 FALSE (that is, compares equal to 0), the assert macro writes information\r
2aa62f2b 60 about the particular call that failed (including the text of the argument,\r
61 the name of the source file, the source line number, and the name of the\r
62 enclosing function - the latter are respectively the values of the\r
63 preprocessing macros __FILE__ and __LINE__ and of the identifier __func__)\r
64 on the standard error stream. It then calls the abort function.\r
65\r
681cc25c 66 If NDEBUG is not defined, Expression is evaluated. If Expression evaluates to FALSE,\r
67 then __assert is called passing in the source filename, source function, source\r
68 line number, and the Expression.\r
2aa62f2b 69\r
70 @param Expression Boolean expression.\r
71\r
72@{\r
73**/\r
74#ifdef NDEBUG\r
75#define assert(Expression) /* ignored */\r
76\r
77#else\r
78#define assert(Expression) ((Expression) ? (void)0 :\\r
681cc25c 79 __assert(__FILE__, __func__, __LINE__, #Expression) )\r
2aa62f2b 80#endif\r
81/// @}\r
82/* END of file assert.h */\r