On Thu, May 07 2020, Michael Forney <[email protected]> wrote:
> I originally submitted this patch as a portability fix to Brian
> Callahan's oksh, but he suggested I submit it here instead.

Out of curiosity, do you run (o)ksh on machines where this matters?

> Conversion of function pointer to void pointer is not allowed in
> ISO C, though POSIX requires it for dlsym(). However, here we are
> also comparing function pointer to void pointer with the == operator
> without using a cast, which is a constraint error[0].
>
> Rather than add a cast, we can just use a typedef here for the
> function pointer type, avoiding any C extensions, and adding a bit
> of type-safety.

Aside from the increased portability, the code doesn't look worse, and
fewer uses of void * is nice.  I'll commit this soon if I don't hear
objections (oks also welcome, obviously).

> [0] https://port70.net/~nsz/c/c11/n1570.html#6.5.9p2
> ---
>  bin/ksh/emacs.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/bin/ksh/emacs.c b/bin/ksh/emacs.c
> index aa2cceb657d..b63735956a3 100644
> --- a/bin/ksh/emacs.c
> +++ b/bin/ksh/emacs.c
> @@ -41,8 +41,10 @@ static     Area    aedit;
>  #define      KEOL    1               /* ^M, ^J */
>  #define      KINTR   2               /* ^G, ^C */
>  
> +typedef int (*kb_func)(int);
> +
>  struct       x_ftab {
> -     int             (*xf_func)(int c);
> +     kb_func         xf_func;
>       const char      *xf_name;
>       short           xf_flags;
>  };
> @@ -861,7 +863,7 @@ x_eot_del(int c)
>               return (x_del_char(c));
>  }
>  
> -static void *
> +static kb_func
>  kb_find_hist_func(char c)
>  {
>       struct kb_entry         *k;
> @@ -1315,7 +1317,7 @@ kb_del(struct kb_entry *k)
>  }
>  
>  static struct kb_entry *
> -kb_add_string(void *func, void *args, char *str)
> +kb_add_string(kb_func func, void *args, char *str)
>  {
>       unsigned int            ele, count;
>       struct kb_entry         *k;
> @@ -1350,7 +1352,7 @@ kb_add_string(void *func, void *args, char *str)
>  }
>  
>  static struct kb_entry *
> -kb_add(void *func, ...)
> +kb_add(kb_func func, ...)
>  {
>       va_list                 ap;
>       unsigned char           ch;

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to