]> granicus.if.org Git - nethack/commitdiff
Define and use PRINTF_F_PTR
authorRay Chason <ray.chason@protonmail.com>
Thu, 3 Nov 2022 23:33:30 +0000 (19:33 -0400)
committerRay Chason <ray.chason@protonmail.com>
Thu, 3 Nov 2022 23:33:30 +0000 (19:33 -0400)
GCCs older than 3.1 understand __attribute__(printf(...)), but only
with functions; it doesn't work with function pointers. This change
uses PRINTF_F_PTR to remove the attribute from two function pointers.

This change establishes GCC 3.0 as the minimum version to build
NetHack. Older versions have trouble with the variadic macros and
variable declarations in mid-block.

include/tradstdc.h
src/mkobj.c
src/vault.c

index d77348f852ba401fc39a77f00102395021b1457d..3681861aa005f59c3463b9eb936d602681132f0b 100644 (file)
@@ -401,6 +401,9 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
 #if (__GNUC__ >= 2) && !defined(USE_OLDARGS)
 #define PRINTF_F(f, v) __attribute__((format(printf, f, v)))
 #endif
+#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+#define PRINTF_F_PTR(f, v) PRINTF_F(f, v)
+#endif
 #if __GNUC__ >= 3
 #define UNUSED __attribute__((unused))
 #define NORETURN __attribute__((noreturn))
@@ -419,6 +422,9 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */
 #ifndef PRINTF_F
 #define PRINTF_F(f, v)
 #endif
+#ifndef PRINTF_F_PTR
+#define PRINTF_F_PTR(f, v)
+#endif
 #ifndef UNUSED
 #define UNUSED
 #endif
index 53f5cf64f7a9f7833889ff70fcf43cc9624e1c26..8f3893c89e89f5e2ae1bc7dbb8c356ec4d234c47 100644 (file)
@@ -761,7 +761,7 @@ static const char dknowns[] = { WAND_CLASS,   RING_CLASS, POTION_CLASS,
 void
 clear_dknown(struct obj *obj)
 {
-    obj->dknown = strchr(dknowns, obj->oclass) ? 0 : 1;
+    obj->dknown = index(dknowns, obj->oclass) ? 0 : 1;
     if ((obj->otyp >= ELVEN_SHIELD && obj->otyp <= ORCISH_SHIELD)
         || obj->otyp == SHIELD_OF_REFLECTION
         || objects[obj->otyp].oc_merge)
@@ -2107,7 +2107,7 @@ place_object(struct obj *otmp, coordxy x, coordxy y)
     register struct obj *otmp2;
 
     if (!isok(x, y)) { /* validate location */
-        void (*func)(const char *, ...) PRINTF_F(1, 2);
+        void (*func)(const char *, ...) PRINTF_F_PTR(1, 2);
 
         func = (x < 0 || y < 0 || x > COLNO - 1 || y > ROWNO - 1) ? panic
                : impossible;
index f86a4b5e2b254d0b673a9a055b38ffca10cfa6ff..18db9adc0a801ac8cd00ca529c9dbc621adc161e 100644 (file)
@@ -413,7 +413,7 @@ invault(void)
            otherwise the hero wouldn't be able to push one to follow the
            guard out of the vault because that guard would be in its way */
         if ((otmp = sobj_at(BOULDER, guard->mx, guard->my)) != 0) {
-            void (*func)(const char *, ...) PRINTF_F(1, 2);
+            void (*func)(const char *, ...) PRINTF_F_PTR(1, 2);
             const char *bname = simpleonames(otmp);
             int bcnt = 0;