]> diplodocus.org Git - nmh/commitdiff
picksbr.c: fprintf(3) function pointer using `%p' and union.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 24 Sep 2017 15:22:15 +0000 (16:22 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 24 Sep 2017 15:22:15 +0000 (16:22 +0100)
Using `%#llx' and cast to `unsigned long long' caused Cygwin woes.
Fixes 07916b2ff.

h/mh.h
sbr/done.c
uip/picksbr.c

diff --git a/h/mh.h b/h/mh.h
index a97a2e4..31cf01b 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -3,6 +3,19 @@
 
 #include <h/nmh.h>
 
+/* It's undefined behaviour in C99 to convert from a function pointer to
+ * a data-object pointer, e.g. void pointer.  gcc's -pedantic warns of
+ * this and can stop compilation.  POSIX requires the operation however,
+ * e.g. for dlsym(3), and so we know it's safe on POSIX platforms, e.g.
+ * the pointers are of the same size.  Thus use a union to subvert gcc's
+ * check.  The function-pointer equivalent of a void pointer is any
+ * function-pointer type as all function pointers are defined to be
+ * convertible from one another;  use the simplest available. */
+typedef union {
+    void *v;
+    void (*f)(void);
+} generic_pointer;
+
 /*
  * Well-used constants
  */
index cd76fac..5f2bc8d 100644 (file)
@@ -7,19 +7,6 @@
 
 #include <h/mh.h>
 
-/* It's undefined behaviour in C99 to convert from a function pointer to
- * a data-object pointer, e.g. void pointer.  gcc's -pedantic warns of
- * this and can stop compilation.  POSIX requires the operation however,
- * e.g. for dlsym(3), and so we know it's safe on POSIX platforms, e.g.
- * the pointers are of the same size.  Thus use a union to subvert gcc's
- * check.  The function-pointer equivalent of a void pointer is any
- * function-pointer type as all function pointers are defined to be
- * convertible from one another;  use the simplest available. */
-typedef union {
-    void *v;
-    void (*f)(void);
-} generic_pointer;
-
 static void (*altexit)(int) NORETURN = exit;
 
 /* set_done changes the path of done() from exit(3), or back to exit(3).
index 432bcf1..2eddab7 100644 (file)
@@ -519,7 +519,10 @@ PRaction (struct nexus *n, int level)
                dasctime (&n->n_tws, TW_NULL));
        return;
     }
-    fprintf(stderr, "UNKNOWN(%#llx)\n", (unsigned long long)n->n_action);
+
+    generic_pointer gp;
+    gp.f = (void (*)(void))n->n_action;
+    fprintf(stderr, "UNKNOWN(%p)\n", gp.v);
 }