From 78545cfb9938c6fe3fdcdc499e7d40c29969bbd4 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Mar 2026 20:38:21 +0100 Subject: [PATCH] Introduce GNU constructor and destructor attributes The constructor attribute causes the function to be called automatically before execution enters main (). Similarly, the destructor attribute causes the function to be called automatically after main () has completed or exit () has been called. Functions with these attributes are useful for initializing data that will be used implicitly during the execution of the program. added "used" attribute aswell so compiler does not omit non referenced functions (i hope) gotta test this a bit but seems cool for stuff like verstable maps --- src/doomdef.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/doomdef.h b/src/doomdef.h index a79b23631..76d426665 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -573,6 +573,13 @@ INT32 I_GetKey(void); // NOTE: you WILL have nasal troubles if the variable is not initialized #define CLEANUP(f) __attribute__((__cleanup__(f))) +// the GNU constructor and destructor attributes +// The constructor attribute causes the function to be called automatically before execution enters main (). +// Similarly, the destructor attribute causes the function to be called automatically after main () has completed or exit () has been called. +// Functions with these attributes are useful for initializing data that will be used implicitly during the execution of the program. +#define CONSTRUCTOR __attribute__((constructor, used)) +#define DESTRUCTOR __attribute__((destructor, used)) + // An assert-type mechanism. #ifdef PARANOIA #define I_Assert(e) ((e) ? (void)0 : I_Error("assert failed: %s, file %s, line %d", #e, __FILE__, __LINE__))