Revision: 71079
          http://sourceforge.net/p/brlcad/code/71079
Author:   starseeker
Date:     2018-06-13 14:03:57 +0000 (Wed, 13 Jun 2018)
Log Message:
-----------
Work around -Wpedantic issue with bu_dlsym and function pointer casting.

Modified Paths:
--------------
    brlcad/trunk/src/gtools/geval.c

Modified: brlcad/trunk/src/gtools/geval.c
===================================================================
--- brlcad/trunk/src/gtools/geval.c     2018-06-13 13:53:25 UTC (rev 71078)
+++ brlcad/trunk/src/gtools/geval.c     2018-06-13 14:03:57 UTC (rev 71079)
@@ -28,6 +28,20 @@
 #include <bu.h>
 #include <ged.h>
 
+/* TODO - we need to make a more generic version of this uglyness part
+ * of a library somewhere... dlsym requires void* to function pointer casting
+ * but in general this is not permitted by ISO C (triggers -Wpedantic):
+ *
+ * https://stackoverflow.com/questions/31526876/casting-when-using-dlsym
+ */
+typedef int (*ged_func_ptr_t)(struct ged *gedp, ...);
+ged_func_ptr_t
+ged_get_func_ptr(void *libged, char *gedfunc)
+{
+    ged_func_ptr_t f;
+    *(void **) (&f) = bu_dlsym(libged, gedfunc);
+    return f;
+}
 
 int
 main(int ac, char *av[]) {
@@ -36,7 +50,7 @@
     struct ged *dbp;
     void *libged = bu_dlopen(NULL, BU_RTLD_LAZY);
     char gedfunc[MAXPATHLEN] = {0};
-    int (*func)(struct ged *gedp, ...);
+    ged_func_ptr_t func;
 
     if (ac < 2) {
        printf("Usage: %s file.g [command]\n", av[0]);
@@ -74,7 +88,7 @@
        return -4;
     }
 
-    func = (int (*)(struct ged *gedp, ...)) bu_dlsym(libged, gedfunc);
+    func = ged_get_func_ptr(libged, gedfunc);
     if (!func) {
        printf("ERROR: unrecognized command [%s]\n", av[0]);
        return -5;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to