5.5.3. Exiting from the program

The program can exit normally at the end of main() or it can exit prematurely because of an error.

See also:

Exiting from an assert

The behavior of the assert macro depends on the conditions in operation at the most recent occurrence of #include <assert.h>:

  1. If the NDEBUG macro is defined (on the command line or as part of a source file), the assert macro has no effect.

  2. If the NDEBUG macro is not defined, the assert expression (the expression given to the assert macro) is evaluated. If the result is TRUE, that is != 0, the assert macro has no further effect.

  3. If the assert expression evaluates to FALSE, the assert macro calls the __aeabi_assert() function if any of the following is true:

    • you are compiling with --strict

    • you are using -O0 or -O1

    • you are compiling with --library_interface=aeabi_clib or --library_interface=aeabi_glibc

    • __ASSERT_MSG is defined

    • _AEABI_PORTABILITY_LEVEL is defined and not 0.

  4. If the assert expression evaluates to FALSE, the assert macro calls abort(). Then:

    1. abort() calls __rt_raise().

    2. If __rt_raise() returns, abort() tries to finalize the library.

If you are creating an application that does not use the library, __aeabi_assert() works if you re-implement abort() and the stdio functions.

Another solution for retargeting is to re-implement the __aeabi_assert() function itself. The function prototype is:

void __aaeabi_ssert(const char *expr, const char *file, int line);

where:

  • expr points to the string representation of the expression that was not TRUE

  • file and line identify the source location of the assertion.

The behavior for __aeabi_assert() supplied in the ARM C library to print a message on stderr and call abort().

You can restore the default behavior for __aeabi_assert() at higher optimization levels by defining __ASSERT_MSG.

Copyright © 2002-2006 ARM Limited. All rights reserved.ARM DUI 0205G
Non-Confidential