1/* Definitions relating to the special __do_global_init function used
2   for getting g++ file-scope static objects constructed.  This file
3   will get included either by libgcc2.c (for systems that don't support
4   a .init section) or by crtstuff.c (for those that do).
5   Copyright (C) 1991, 1995, 1996, 1998 Free Software Foundation, Inc.
6   Contributed by Ron Guilmette (rfg@segfault.us.com)
7
8This file is part of GNU CC.
9
10GNU CC is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2, or (at your option)
13any later version.
14
15GNU CC is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with GNU CC; see the file COPYING.  If not, write to
22the Free Software Foundation, 59 Temple Place - Suite 330,
23Boston, MA 02111-1307, USA.  */
24
25/*	This file contains definitions and declarations of things
26	relating to the normal start-up-time invocation of C++
27	file-scope static object constructors.  These declarations
28	and definitions are used by *both* libgcc2.c and by crtstuff.c.
29
30	Note that this file should only be compiled with GCC.
31*/
32
33#ifdef NEED_ATEXIT
34#ifndef HAVE_ATEXIT
35#define HAVE_ATEXIT	1	/* Take it from libgcc2.c */
36#endif
37#endif
38
39#ifdef HAVE_ATEXIT
40#if defined (WINNT) || defined (NEED_ATEXIT)
41extern int atexit (void (*) (void));
42#endif
43#define ON_EXIT(FUNC,ARG) atexit ((FUNC))
44#else
45#ifdef sun
46extern int on_exit (void *, void *);	/* The man page says it returns int. */
47#define ON_EXIT(FUNC,ARG) on_exit ((FUNC), (ARG))
48#endif
49#endif
50
51/*  Declare a pointer to void function type.  */
52
53typedef void (*func_ptr) (void);
54
55/* Declare the set of symbols use as begin and end markers for the lists
56   of global object constructors and global object destructors.  */
57
58extern func_ptr __CTOR_LIST__[];
59extern func_ptr __DTOR_LIST__[];
60
61/* Declare the routine which need to get invoked at program exit time.  */
62
63extern void __do_global_dtors (void);
64
65/* Define a macro with the code which needs to be executed at program
66   start-up time.  This macro is used in two places in crtstuff.c (for
67   systems which support a .init section) and in one place in libgcc2.c
68   (for those system which do *not* support a .init section).  For all
69   three places where this code might appear, it must be identical, so
70   we define it once here as a macro to avoid various instances getting
71   out-of-sync with one another.  */
72
73/* Some systems place the number of pointers
74   in the first word of the table.
75   On other systems, that word is -1.
76   In all cases, the table is null-terminated.
77   If the length is not recorded, count up to the null.  */
78
79/* Some systems use a different strategy for finding the ctors.
80   For example, svr3.  */
81#ifndef DO_GLOBAL_CTORS_BODY
82#define DO_GLOBAL_CTORS_BODY						\
83do {									\
84  unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];		\
85  unsigned i;								\
86  if (nptrs == (unsigned long)-1)				        \
87    for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);		\
88  for (i = nptrs; i >= 1; i--)						\
89    __CTOR_LIST__[i] ();						\
90} while (0)
91#endif
92
93