1
The collector uses a large amount of conditional compilation in order to
2
deal with platform dependencies. This violates a number of known coding
3
standards. On the other hand, it seems to be the only practical way to
4
support this many platforms without excessive code duplication.
6
A few guidelines have mostly been followed in order to keep this manageable:
8
1) #if and #ifdef directives are properly indented whenever easily possible.
9
All known C compilers allow whitespace between the "#" and the "if" to make
10
this possible. ANSI C also allows white space before the "#", though we
11
avoid that. It has the known disadvantages that it differs from the normal
12
GNU conventions, and that it makes patches larger than otherwise necessary.
13
In my opinion, it's still well worth it, for the same reason that we indent
14
ordinary "if" statements.
16
2) Whenever possible, tests are performed on the macros defined in gcconfig.h
17
instead of directly testing patform-specific predefined macros. This makes it
18
relatively easy to adapt to new compilers with a different set of predefined
19
macros. Currently these macros generally identify platforms instead of
20
features. In many cases, this is a mistake.
22
Many of the tested configuration macros are at least somewhat defined in
23
either include/private/gcconfig.h or in Makefile.direct. Here is an attempt
24
at defining some of the remainder: (Thanks to Walter Bright for suggesting
25
this. This is a work in progress)
30
__DMC__ Always #define'd by the Digital Mars compiler. Expands
31
to the compiler version number in hex, i.e. 0x810 is
35
#define'd by the Digital Mars C++ compiler when
36
operator new[] and delete[] are separately
37
overloadable. Used in gc_cpp.h.
39
_MSC_VER Expands to the Visual C++ compiler version. Assumed to
40
not be defined for other compilers (at least if they behave
41
appreciably differently).
43
_DLL Defined by Visual C++ if dynamic libraries are being built
44
or used. Used to test whether __declspec(dllimport) or
45
__declspec(dllexport) needs to be added to declarations
46
to support the case in which the collector is in a dll.
48
GC_DLL User-settable macro that forces the effect of _DLL. Set
49
by gc.h if _DLL is defined and GC_NOT_DLL is undefined.
50
This is the macro that is tested internally to determine
51
whether the GC is in its own dynamic library. May need
52
to be set by clients before including gc.h. Note that
53
inside the GC implementation it indicates that the
54
collector is in its own dynamic library, should export
55
its symbols, etc. But in clients it indicates that the
56
GC resides in a different DLL, its entry points should
57
be referenced accordingly, and precautions may need to
58
be taken to properly deal with statically allocated
59
variables in the main program. Used only for MS Windows.
61
GC_NOT_DLL User-settable macro that overrides _DLL, e.g. if dynamic
62
libraries are used, but the collector is in a static library.
64
__STDC__ Assumed to be defined only by compilers that understand
65
prototypes and other C89 features. Its value is generally
66
not used, since we are fine with most nonconforming extensions.
68
SUNOS5SIGS Solaris-like signal handling. This is probably misnamed,
69
since it really doesn't guarantee much more than Posix.
70
Currently set only for Solaris2.X, HPUX, and DRSNX. Should
71
probably be set for some other platforms.
73
PCR Set if the collector is being built as part of the Xerox
74
Portable Common Runtime.
76
USE_COMPILER_TLS Assume the existence of __thread-style thread-local
77
storage. Set automatically for thread-local allocation with
78
the HP/UX vendor compiler. Usable with gcc on sufficiently
79
up-to-date ELF platforms.