tenox7 / ttyplot

a realtime plotting utility for terminal/console with data input from stdin
Apache License 2.0
961 stars 43 forks source link

Fix signal handler function signatures #70

Closed hartwork closed 1 year ago

hartwork commented 1 year ago

Previously, e.g. GCC 11 was warning:

# CFLAGS='-std=gnu99 -pedantic' make
cc -std=gnu99 -pedantic -Wall -Wextra    ttyplot.c  -lncurses -ltinfo -o ttyplot
ttyplot.c: In function ‘main’:
ttyplot.c:291:22: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
  291 |     signal(SIGWINCH, (void*)resize);
      |                      ^
ttyplot.c:291:22: warning: ISO C forbids passing argument 2 of ‘signal’ between function pointer and ‘void *’ [-Wpedantic]
  291 |     signal(SIGWINCH, (void*)resize);
      |                      ^~~~~~~~~~~~~
In file included from ttyplot.c:15:
/usr/include/signal.h:88:57: note: expected ‘__sighandler_t’ {aka ‘void (*)(int)’} but argument is of type ‘void *’
   88 | extern __sighandler_t signal (int __sig, __sighandler_t __handler)
      |                                          ~~~~~~~~~~~~~~~^~~~~~~~~
ttyplot.c:292:20: warning: ISO C forbids conversion of function pointer to object pointer type [-Wpedantic]
  292 |     signal(SIGINT, (void*)finish);
      |                    ^
ttyplot.c:292:20: warning: ISO C forbids passing argument 2 of ‘signal’ between function pointer and ‘void *’ [-Wpedantic]
  292 |     signal(SIGINT, (void*)finish);
      |                    ^~~~~~~~~~~~~
In file included from ttyplot.c:15:
/usr/include/signal.h:88:57: note: expected ‘__sighandler_t’ {aka ‘void (*)(int)’} but argument is of type ‘void *’
   88 | extern __sighandler_t signal (int __sig, __sighandler_t __handler)
      |                                          ~~~~~~~~~~~~~~~^~~~~~~~~
tenox7 commented 1 year ago

thank you for the submission, I need to verify how that works on older unixes

hartwork commented 1 year ago

Okay sure. The OpenGroup POSIX page for signal is at https://pubs.opengroup.org/onlinepubs/009604499/functions/signal.html . Are we talking POSIX?

hartwork commented 1 year ago

PS: My local man 2 signal says:

STANDARDS
       POSIX.1-2001, POSIX.1-2008, C99.

If C99 is reality, that would be great.

hartwork commented 1 year ago

can you explain what does (void)signum; do here?

@tenox7 that's most portable way to mark a variable as unused that I know. There are other ways but probably less portable, e.g. see https://stackoverflow.com/questions/3599160/how-can-i-suppress-unused-parameter-warnings-in-c . What do you think?

tenox7 commented 1 year ago

I see. Thank you! Let me look on how it works on other systems.