home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / gnulib / rcs / gbl-ctors.h,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  3.3 KB  |  115 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.1
  10. date    92.06.08.19.47.59;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @initial checkin
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* Definitions relating to the special __do_global_init function used
  26.    for getting g++ file-scope static objects constructed.  This file
  27.    wil get included either by gnulib2.c (for systems that don't support
  28.    a .init section) or by crtstuff.c (for those that do).
  29.  
  30.    Written by Ron Guilmette (rfg@@ncd.com)
  31.  
  32. Copyright (C) 1991 Free Software Foundation, Inc.
  33.  
  34. This file is part of GNU CC.
  35.  
  36. GNU CC is free software; you can redistribute it and/or modify
  37. it under the terms of the GNU General Public License as published by
  38. the Free Software Foundation; either version 2, or (at your option)
  39. any later version.
  40.  
  41. GNU CC is distributed in the hope that it will be useful,
  42. but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  44. GNU General Public License for more details.
  45.  
  46. You should have received a copy of the GNU General Public License
  47. along with GNU CC; see the file COPYING.  If not, write to
  48. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  49.  
  50. /*    This file contains definitions and declarations of things
  51.     relating to the normal start-up-time invocation of C++
  52.     file-scope static object constructors.  These declarations
  53.     and definitions are used by *both* gnulib2.c and by crtstuff.c.
  54.  
  55.     Note that this file should only be compiled with GCC.
  56. */
  57.  
  58. #ifdef sun
  59. extern void on_exit (void*, void*);
  60. #define ON_EXIT(FUNC,ARG) on_exit ((FUNC), (ARG))
  61. #else
  62. #ifdef HAVE_ATEXIT
  63. extern void atexit (void (*) (void));
  64. #define ON_EXIT(FUNC,ARG) atexit ((FUNC))
  65. #endif
  66. #endif
  67.  
  68. /*  Declare a pointer to void function type.  */
  69.  
  70. typedef void (*func_ptr) (void);
  71.  
  72. /* Declare the set of symbols use as begin and end markers for the lists
  73.    of global object constructors and global object descructors.  */
  74.  
  75. extern func_ptr __CTOR_LIST__[];
  76. extern func_ptr __CTOR_END__[];
  77. extern func_ptr __DTOR_LIST__[];
  78. extern func_ptr __DTOR_END__[];
  79.  
  80. /* Declare the routine which need to get invoked at program exit time.  */
  81.  
  82. extern void __do_global_dtors ();
  83.  
  84. /* Define a macro with the code which needs to be executed at program
  85.    start-up time.  This macro is used in two places in crtstuff.c (for
  86.    systems which support a .init section) and in one place in gnulib2.c
  87.    (for those system which do *not* support a .init section).  For all
  88.    three places where this code might appear, it must be identical, so
  89.    we define it once here as a macro to avoid various instances getting
  90.    out-of-sync with one another.  */
  91.  
  92. /* There are two formats for the table __CTOR_LIST__:
  93.    GNU ld: first word is number of pointers, followed by that many pointers.
  94.    ELF/COFF: first word is -1, followed by pointers up to __CTOR_END__.  */
  95.  
  96. #define DO_GLOBAL_CTORS_BODY                        \
  97. do {                                    \
  98.   int nptrs = *(int *)__CTOR_LIST__;                    \
  99.   ON_EXIT (__do_global_dtors, 0);                    \
  100.   if (nptrs != -1)                            \
  101.     {                                    \
  102.       int i;                                \
  103.       for (i = 1; i <= nptrs; i++)                    \
  104.     __CTOR_LIST__[i] ();                        \
  105.     }                                    \
  106.   else                                    \
  107.     {                                    \
  108.       func_ptr *p;                            \
  109.       for (p = __CTOR_LIST__ + 1; p < __CTOR_END__; )            \
  110.         (*p++) ();                            \
  111.     }                                    \
  112. } while (0)
  113.  
  114. @
  115.