Skip to content

[config] Defining custom allocator macros in src/config.h results in: warning: "RL_*ALLOC" redefined #4778

Closed
@sleeptightAnsiC

Description

@sleeptightAnsiC

While working on other issue ( #4777 / #4776 ) I noticed that src/raylib.h defines "RL_*ALLOC" macros before including src/config.h (raylib.h does not include config.h at all). If someone tries to define said macros inside config.h (which seems like very reasonable place) it will result in compiler warnings about that said macros were re-defined. This may also indicate that a mismatch happens somewhere during preprocessing stage.

Repro:

with the patch below applied to config.h

diff --git a/src/config.h b/src/config.h
index f7b01530..fd108d9a 100644
--- a/src/config.h
+++ b/src/config.h
@@ -28,6 +28,12 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
+#include <stdlib.h> // puts
+#include <stdio.h>  // malloc realloc free
+#define RL_MALLOC(...) (puts(__func__), malloc(__VA_ARGS__))
+#define RL_REALLOC(...) (puts(__func__), realloc(__VA_ARGS__))
+#define RL_FREE(...) (puts(__func__), free(__VA_ARGS__))
+
 //------------------------------------------------------------------------------------
 // Module selection - Some modules could be avoided
 // Mandatory modules: rcore, rlgl, utils

try to compile with Cmake or GNU Make

$ make
gcc -c rcore.c -Wall -D_GNU_SOURCE -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_33 -Wno-missing-braces -Werror=pointer-arith -fno-strict-aliasing -std=c99 -fPIC -O1 -Werror=implicit-function-declaration -D_GLFW_X11  -I.  -Iexternal/glfw/include
In file included from rcore.c:109:
config.h:33:9: warning: "RL_MALLOC" redefined
   33 | #define RL_MALLOC(...) (puts(__func__), malloc(__VA_ARGS__))
      |         ^~~~~~~~~
In file included from rcore.c:105:
raylib.h:138:13: note: this is the location of the previous definition
  138 |     #define RL_MALLOC(sz)       malloc(sz)
      |             ^~~~~~~~~
config.h:34:9: warning: "RL_REALLOC" redefined
   34 | #define RL_REALLOC(...) (puts(__func__), realloc(__VA_ARGS__))
      |         ^~~~~~~~~~
raylib.h:144:13: note: this is the location of the previous definition
  144 |     #define RL_REALLOC(ptr,sz)  realloc(ptr,sz)
      |             ^~~~~~~~~~
config.h:35:9: warning: "RL_FREE" redefined
   35 | #define RL_FREE(...) (puts(__func__), free(__VA_ARGS__))
      |         ^~~~~~~
raylib.h:147:13: note: this is the location of the previous definition
  147 |     #define RL_FREE(ptr)        free(ptr)
      |             ^~~~~~~

(this is x86_64 Linux with raylib pulled from git)

$ uname -a
Linux MAL200424 6.13.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 08 Feb 2025 18:54:55 +0000 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions