Carmack may be brilliant, but fuck this. Low-level programmers, indeed.

roll-your-own offsetof, disgusting.

fix on LP64 + gcc4
This commit is contained in:
espie 2010-06-07 16:03:40 +00:00
parent 80c825b486
commit 90d29551f7
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,19 @@
$OpenBSD: patch-src_baseq2_g_local_h,v 1.1 2010/06/07 16:03:40 espie Exp $
--- src/baseq2/g_local.h.orig Mon Jun 7 17:57:55 2010
+++ src/baseq2/g_local.h Mon Jun 7 17:58:55 2010
@@ -505,10 +505,11 @@ extern int meansOfDeath;
extern edict_t *g_edicts;
-#define FOFS(x) (int)&(((edict_t *)0)->x)
-#define STOFS(x) (int)&(((spawn_temp_t *)0)->x)
-#define LLOFS(x) (int)&(((level_locals_t *)0)->x)
-#define CLOFS(x) (int)&(((gclient_t *)0)->x)
+#include <stddef.h>
+#define FOFS(x) offsetof(edict_t, x)
+#define STOFS(x) offsetof(spawn_temp_t, x)
+#define LLOFS(x) offsetof(level_locals_t, x)
+#define CLOFS(x) offsetof(gclient_t, x)
#define random() ((rand () & 0x7fff) / ((float)0x7fff))
#define crandom() (2.0 * (random() - 0.5))

View File

@ -0,0 +1,19 @@
$OpenBSD: patch-src_ctf_g_local_h,v 1.1 2010/06/07 16:03:40 espie Exp $
--- src/ctf/g_local.h.orig Mon Jun 7 18:00:36 2010
+++ src/ctf/g_local.h Mon Jun 7 18:01:30 2010
@@ -514,10 +514,11 @@ extern int meansOfDeath;
extern edict_t *g_edicts;
-#define FOFS(x) (int)&(((edict_t *)0)->x)
-#define STOFS(x) (int)&(((spawn_temp_t *)0)->x)
-#define LLOFS(x) (int)&(((level_locals_t *)0)->x)
-#define CLOFS(x) (int)&(((gclient_t *)0)->x)
+#include <stddef.h>
+#define FOFS(x) offsetof(edict_t, x)
+#define STOFS(x) offsetof(spawn_temp_t, x)
+#define LLOFS(x) offsetof(level_locals_t, x)
+#define CLOFS(x) offsetof(gclient_t, x)
#define random() ((rand () & 0x7fff) / ((float)0x7fff))
#define crandom() (2.0 * (random() - 0.5))

View File

@ -0,0 +1,17 @@
$OpenBSD: patch-src_sv_world_c,v 1.1 2010/06/07 16:03:40 espie Exp $
--- src/sv_world.c.orig Mon Jun 7 17:49:42 2010
+++ src/sv_world.c Mon Jun 7 17:56:40 2010
@@ -30,10 +30,12 @@ FIXME: this use of "area" is different from the bsp fi
===============================================================================
*/
+#include <stddef.h>
+
// (type *)STRUCT_FROM_LINK(link_t *link, type, member)
// ent = STRUCT_FROM_LINK(link,entity_t,order)
// FIXME: remove this mess!
-#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
+#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - offsetof(t, m)))
#define EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edict_t,area)