GLib Compiler Requirements
GLib makes some assumptions about features of the C library and C preprocessor, compiler and linker that go beyond C89. We will use features beyond C89 if they are substantially useful and if they are supported in a wide range of compilers.
In general, we are primarily interested in supporting these four compilers:
- GCC on *nix
- Clang (LLVM)
This is in keeping with our goal of primarily targetting GNU/Linux, Windows and Mac OS, along with Free Software POSIX-complaint operating systems. See Supported platforms for a bit more information and rationale about that.
In particular, we are interested in MSVC because, although there are other compilers which target Windows, they do not output debugging information that is compatible with MSVC. In interest of usability, we want users of GLib to be able to debug GLib along with their own code while using MSVC as their development environment.
At any given time, GLib may work with mingw32 (from mingw.org) but it is not specifically supported. Politics aside, it seems that mingw.org is mostly dormant and, at this point, all of the big distributions have switched over to mingw32-w64. In several cases, mingw.org has been missing APIs that we've wanted to use and upstream has not been responsive about adding them.
GLib will attempt to remain compatible with other compilers, but some 'extra features' are assumed. Those are detailed below.
GLib additionally requires Python 3 to build.
Not a hard requirement. GLib can work with either C99 or GNU style varargs macros.
Symbol visibility control
Not a hard requirement. When available, GLib uses __attribute__((visibility("hidden"))) and the -fvisibility=hidden compiler option to control symbol visibility, and the -Bsymbolic-functions linker flag.
Builtin atomic operations
Not a hard requirement. GLib will fall back to using a mutex-based implementation if atomic builtins are not available.
C99 printf and positional parameters
Not a hard requirement. GLib can be built with an included printf implementation (from GNUlib) if the system printf is deficient.
Constructors and destructors
Hard requirement. GLib can work with pragma-based, as well as with attribute-based constructor support. There is a fallback for msvc using a DllMain() instead.
GLib depends on the ability to pass-by-reference a va_list, as mandated in C99 § 7.15: “It is permitted to create a pointer to a va_list and pass that pointer to another function, in which case the original function may make further use of the original list after the other function returns.”
Support for 'static inline'
GLib depends on implementation of the inline keyword as described by C99 § 6.7.4.
GLib further assumes that functions appearing in header files and marked static inline, but not used in a particular compilation unit will:
- not generate warnings about being unused
- not be emitted in the compiler's output
It is possible that a compiler adheres to C99 § 6.7.4 but not to GLib's further assumptions. Such compilers may produce large numbers of warnings or large executables when compiling GLib or programs based on GLib.
Support for alloca()
Your compiler must support alloca(), defined in <alloca.h> (or <malloc.h> on Windows) and it must accept a non-constant argument.
(C11) support for type redefinition
This requirement has been temporarily suspended (on account of OpenBSD carrying an old version of gcc) but it will probably return in the future.
Your compiler must allow "a typedef name [to] be redefined to denote the same type as it currently does", as per C11 §6.7, item 3.
Some of our enum types use 1<<31 as a value. We also use negative values in enums. We rely on the compiler to choose a suitable storage size for the enum that can accommodate this.
Selected C99 features
Starting with GLib 2.52 and GTK+ 3.90, we will be using the following C99 features where appropriate:
- Compound literals
- Designated initializers
- Mixed declarations
Function pointer conversions
GLib heavily relies on the ability to convert a function pointer to a void* and back again losslessly. Any platform or compiler which doesn’t support this cannot be used to compile GLib or code which uses GLib. This precludes use of the -pedantic GCC flag with GLib.