less icon indicating copy to clipboard operation
less copied to clipboard

screen.c:1376:22: warning: passing argument 3 of 'tputs' from incompatible pointer type

Open Mno-hime opened this issue 5 years ago • 9 comments

Compiling less 551 with GCC 6.5.0 on OpenIndiana 2019.04 (an illumos distribution) brings quite some warnings, all of them are from line 1376 to 2403 in the screen.c file and look like this:

/export/home/newman/ws/oi-userland/components/text/less/less-551/screen.c: In function 'cost':
/export/home/newman/ws/oi-userland/components/text/less/less-551/screen.c:1376:22: warning: passing argument 3 of 'tputs' from incompatible pointer type [-Wincompatible-pointer-types]
  tputs(t, sc_height, inc_costcount);
                      ^~~~~~~~~~~~~
In file included from /export/home/newman/ws/oi-userland/components/text/less/less-551/screen.c:59:0:
/usr/include/termcap.h:47:12: note: expected 'int (*)(char)' but argument is of type 'int (*)()'
 extern int tputs(char *, int, int (*)(char));
            ^~~~~

Mno-hime avatar Jun 12 '19 05:06 Mno-hime

This seems like a bug in that version of gcc. inc_costcount is defined with a parameter. And gcc 10.2.1 does not print this message, even with -Wall.

gwsw avatar Mar 05 '21 17:03 gwsw

With GCC 10.2.0 I still get following two warnings when compiling less 580:

/usr/gcc/10/bin/gcc -I. -c -DBINDIR=\"/usr/bin\" -DSYSDIR=\"/usr/etc\"  -m64 -O3  /export/home/newman/oi-userland/components/text/less/less-580/screen.c
/export/home/newman/oi-userland/components/text/less/less-580/screen.c: In function 'cost':
/export/home/newman/oi-userland/components/text/less/less-580/screen.c:1411:22: warning: passing argument 3 of 'tputs' from incompatible pointer type [-Wincompatible-pointer-types]
 1411 |  tputs(t, sc_height, inc_costcount);
      |                      ^~~~~~~~~~~~~
      |                      |
      |                      int (*)()
In file included from /export/home/newman/oi-userland/components/text/less/less-580/screen.c:72:
/usr/include/termcap.h:47:31: note: expected 'int (*)(char)' but argument is of type 'int (*)()'
   47 | extern int tputs(char *, int, int (*)(char));
      |                               ^~~~~~~~~~~~~
/export/home/newman/oi-userland/components/text/less/less-580/screen.c: In function 'do_tputs':
/export/home/newman/oi-userland/components/text/less/less-580/screen.c:1619:22: warning: passing argument 3 of 'tputs' from incompatible pointer type [-Wincompatible-pointer-types]
 1619 |   tputs(str, affcnt, f_putc);
      |                      ^~~~~~
      |                      |
      |                      int (*)(int)
In file included from /export/home/newman/oi-userland/components/text/less/less-580/screen.c:72:
/usr/include/termcap.h:47:31: note: expected 'int (*)(char)' but argument is of type 'int (*)(int)'
   47 | extern int tputs(char *, int, int (*)(char));
      |                               ^~~~~~~~~~~~~

illumos has it's own curses implementation, which is the default, so it might be that but from what I see ncurses 6.2.20200212 gets picked:

configure:3708: checking for initscr in -lxcurses
configure:3733: /usr/gcc/10/bin/gcc -o conftest -m64 -O3   -m64 conftest.c -lxcurses   >&5
ld: fatal: library -lxcurses: not found
ld: fatal: file processing errors. No output written to conftest
collect2: error: ld returned 1 exit status
configure:3733: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "less"
| #define PACKAGE_TARNAME "less"
| #define PACKAGE_VERSION "1"
| #define PACKAGE_STRING "less 1"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
|
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char initscr ();
| int
| main ()
| {
| return initscr ();
|   ;
|   return 0;
| }
configure:3742: result: no
configure:3750: checking for initscr in -lncursesw
configure:3775: /usr/gcc/10/bin/gcc -o conftest -m64 -O3   -m64 conftest.c -lncursesw   >&5
configure:3775: $? = 0
configure:3784: result: yes
configure:3792: checking for initscr in -lncurses
configure:3817: /usr/gcc/10/bin/gcc -o conftest -m64 -O3   -m64 conftest.c -lncurses   >&5
configure:3817: $? = 0
configure:3826: result: yes
configure:3834: checking for initscr in -lcurses
configure:3859: /usr/gcc/10/bin/gcc -o conftest -m64 -O3   -m64 conftest.c -lcurses   >&5
configure:3859: $? = 0
configure:3868: result: yes
configure:3876: checking for tgetent in -ltermcap
configure:3901: /usr/gcc/10/bin/gcc -o conftest -m64 -O3   -m64 conftest.c -ltermcap   >&5
configure:3901: $? = 0
configure:3910: result: yes
configure:3918: checking for tgetent in -ltermlib
configure:3943: /usr/gcc/10/bin/gcc -o conftest -m64 -O3   -m64 conftest.c -ltermlib   >&5
configure:3943: $? = 0
configure:3952: result: yes
configure:3962: checking for library containing regcmp
configure:3993: /usr/gcc/10/bin/gcc -o conftest -m64 -O3   -m64 conftest.c  >&5
configure:3993: $? = 0
configure:4010: result: none required
configure:4020: checking for working terminal libraries
configure:4141: /usr/gcc/10/bin/gcc -o conftest -m64 -O3   -m64 conftest.c  -lncursesw >&5
conftest.c: In function 'main':
conftest.c:13:1: warning: implicit declaration of function 'tgetent' [-Wimplicit-function-declaration]
   13 | tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);
      | ^~~~~~~
conftest.c:13:15: warning: implicit declaration of function 'tgetflag' [-Wimplicit-function-declaration]
   13 | tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);
      |               ^~~~~~~~
conftest.c:13:28: warning: implicit declaration of function 'tgetnum' [-Wimplicit-function-declaration]
   13 | tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);
      |                            ^~~~~~~
conftest.c:13:40: warning: implicit declaration of function 'tgetstr' [-Wimplicit-function-declaration]
   13 | tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);
      |                                        ^~~~~~~
configure:4141: $? = 0
configure:4306: result: using -lncursesw

Mno-hime avatar Mar 05 '21 18:03 Mno-hime

Well, I'm baffled by this. inc_costcount is clearly defined with a parameter in less-580:

    static int
inc_costcount(c)
    int c;
{

So I don't understand why the compiler says that the type is 'int (*)()' rather than 'int (*)(int)'. I do not see this warning with gcc 10.2.0 on MacOS using -lncurses or 10.2.1 on Linux using -ltinfo. I wonder if it has something to do with the K&R function definition. Does the warning go away if you manually edit the definition of inc_costcount like this?

    static int
inc_costcount(int c)
{

gwsw avatar May 01 '21 19:05 gwsw

We are seeing similar failures in build less with ToT clang:

less-590: configure:4231: x86_64-cros-linux-gnu-clang -o conftest -Os -pipe -march=goldmont -g -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -Wl,-O2 -Wl,--as-needed -Wl,--gc-sections -Wl,--icf=all conftest.c -lcurses >&5 less-590: conftest.c:13:1: error: call to undeclared function 'tgetent'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] less-590: tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0); less-590: ^ less-590: conftest.c:13:15: error: call to undeclared function 'tgetflag'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] less-590: tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0); less-590: ^ less-590: conftest.c:13:28: error: call to undeclared function 'tgetnum'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] less-590: tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0); less-590: ^ less-590: conftest.c:13:40: error: call to undeclared function 'tgetstr'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] less-590: tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0); less-590: ^ less-590: 4 errors generated. less-590: configure:4231: $? = 1 less-590: configure: failed program was: less-590: | /* confdefs.h / less-590: | #define PACKAGE_NAME "less" less-590: | #define PACKAGE_TARNAME "less" less-590: | #define PACKAGE_VERSION "1" less-590: | #define PACKAGE_STRING "less 1" less-590: | #define PACKAGE_BUGREPORT "" less-590: | #define PACKAGE_URL "" less-590: | / end confdefs.h. */ less-590: | less-590: | int less-590: | main () less-590: | { less-590: | tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0); less-590: | ; less-590: | return 0; less-590: | } less-590: configure:4334: result: Cannot find terminal libraries - configure failed

m-gupta avatar Apr 29 '22 00:04 m-gupta

This is not the same issue as the original report. In your case it appears configure is not finding a terminal library (one of tinfo, tinfow, xcurses, ncursesw, ncurses, curses, termcap, or termlib). Which of these are installed on your build system?

gwsw avatar Apr 29 '22 03:04 gwsw

Problem is with ToT clang, -Wimplicit-function-declaration has been promoted to an error. So the compile fails.

less-590: conftest.c:13:40: error: call to undeclared function 'tgetstr'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

If I forcefully set -Wno-error as CFLAGS, then the build works fine.

m-gupta avatar Apr 29 '22 03:04 m-gupta

This is a godbolt link to show the issue: https://godbolt.org/z/GEsxxPjnK

Note that one possible fix the issue will be to add compiler flag "-std=gnu89"

m-gupta avatar Apr 29 '22 04:04 m-gupta

@m-gupta could you try 1101069ae7157aa57a4c58ac9731e271bec7e4d9 and see if the build now works with clang?

gwsw avatar May 01 '22 17:05 gwsw

thanks, yes it works now.

m-gupta avatar May 01 '22 20:05 m-gupta