fork(1) download
  1. # include <stdio.h>
  2.  
  3. /* Demo code showing the usage of the cleanup variable
  4.   attribute. See:http://g...content-available-to-author-only...u.org/onlinedocs/gcc/Variable-Attributes.html
  5.   */
  6.  
  7. /* cleanup function
  8.   the argument is a int * to accept the address
  9.   to the final value
  10.   */
  11.  
  12. void clean_up(int *final_value)
  13. {
  14. printf("Cleaning up\n");
  15. printf("Final value: %d\n",*final_value);
  16.  
  17. }
  18.  
  19. int main(int argc, char **argv)
  20. {
  21. /* declare cleanup attribute along with initiliazation
  22.   Without the cleanup attribute, this is equivalent
  23.   to:
  24.   int avar = 1;
  25.   */
  26.  
  27. int avar __attribute__ ((__cleanup__(clean_up))) = 1;
  28. avar = 5;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
Cleaning up
Final value: 5