Ethereal-dev: [Ethereal-dev] Plrave review: Functioncasting in lemon.c

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Joerg Mayer <jmayer@xxxxxxxxx>
Date: Sat, 24 Jan 2004 15:56:25 +0100
Can someone please have a look whether I got the function casting right
this time?

Thanks
    Jörg
-- 
Joerg Mayer                                           <jmayer@xxxxxxxxx>
We are stuck with technology when what we really want is just stuff that
works. Some say that should read Microsoft instead of technology.
Index: lemon.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/tools/lemon/lemon.c,v
retrieving revision 1.16
diff -p -u -r1.16 lemon.c
--- lemon.c	18 Jan 2004 15:53:43 -0000	1.16
+++ lemon.c	24 Jan 2004 14:50:18 -0000
@@ -1490,6 +1490,10 @@ static int argindex(int n)
 
 static char emsg[] = "Command line syntax error: ";
 
+typedef void (opt_func_int_t)(int);
+typedef void (opt_func_double_t)(double);
+typedef void (opt_func_string_t)(char*);
+
 /*
 ** Process a flag command line argument.
 */
@@ -1511,7 +1515,7 @@ static int handleflags(int i, FILE *err)
   }else if( op[j].type==OPT_FLAG ){
     *((int*)op[j].arg) = v;
   }else if( op[j].type==OPT_FFLAG ){
-    (*(void(*)())(op[j].arg))(v);
+    ((opt_func_int_t*)(op[j].arg))(v);
   }else{
     if( err ){
       fprintf(err,"%smissing argument on switch.\n",emsg);
@@ -1591,19 +1595,19 @@ static int handleswitch(int i, FILE *err
         *(double*)(op[j].arg) = dv;
         break;
       case OPT_FDBL:
-        (*(void(*)())(op[j].arg))(dv);
+        ((opt_func_double_t*)(op[j].arg))(dv);
         break;
       case OPT_INT:
         *(int*)(op[j].arg) = lv;
         break;
       case OPT_FINT:
-        (*(void(*)())(op[j].arg))((int)lv);
+        ((opt_func_int_t*)(op[j].arg))(lv);
         break;
       case OPT_STR:
         *(char**)(op[j].arg) = sv;
         break;
       case OPT_FSTR:
-        (*(void(*)())(op[j].arg))(sv);
+        ((opt_func_string_t*)(op[j].arg))(sv);
         break;
     }
   }