10.36 __attribute__((destructor[(priority)])) function attribute

This attribute causes the function it is associated with to be called automatically after main() completes or after exit() is called.

Note

This attribute is a GNU compiler extension that the ARM compiler supports.

Syntax

__attribute__((destructor[(priority)]))

Where priority is an optional integer value denoting the priority. A destructor with a high integer value runs before a destructor with a low value. A destructor with a priority runs before a destructor without a priority.

Priority values up to and including 100 are reserved for internal use. If you use these values, the compiler gives a warning. Priority values above 100 are not reserved.

Usage

This attribute can be preferable to the linker option --fini=symbol if you are using GNU makefiles unmodified to build with the ARM compiler. That is, if you are using --translate_gcc, --translate_gld, or --translate_g++.

Examples

int my_destructor(void) __attribute__((destructor));
int my_destructor(void) /* This function is called after main() */
{                       /* completes or after exit() is called. */
   ...
   return 0;
}
Related reference
10.34 __attribute__((constructor[(priority)])) function attribute
8.178 --translate_g++
8.179 --translate_gcc
8.180 --translate_gld
Related information
--fini=symbol linker option
Non-ConfidentialPDF file icon PDF versionARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.