abakh / nbsdgames

A package of 18 text-based modern games
Other
208 stars 16 forks source link

Doesn't compile with --std=c99 #20

Closed clausecker closed 3 years ago

clausecker commented 3 years ago

The package currently fails to build on PPC64 FreeBSD 13.0. The reason for this failure is that the PPC64 version of FreeBSD still uses a fairly old gcc version that defaults to C89, so there are a bunch of errors. Switching to C99 makes some of these go away but exposes new problems: your code apparently redefines a byte type a bunch of times:

jewels.c:27:21: warning: redefinition of typedef 'byte' is a C11 feature [-Wtypedef-redefinition]
typedef signed char byte;
                    ^
./common.h:17:21: note: previous definition is here
typedef signed char byte;
                    ^
1 warning generated.

(while this is a warning with the version of clang I tested, I believe it is an error on the old gcc).

Please fix the code by removing all duplicate definitions of byte. There should only be one such definition in common.h. Then make a new release so I can package the fix. You can check if you fixed it correctly by temporarily adding --std=c99 to CFLAGS.

abakh commented 3 years ago

Yes, I confronted that problem on old gcc myself but didn't get the opportunity to fix it. Is it fixed now?

clausecker commented 3 years ago

Nope, still not correct. Try to compile with

make CC="cc --std=c99 -Wall"

to see the warnings. Consider adding include guards to config.h. Also, M_PI is defined in math.h. Instead of manually defining it, just include the math.h header.

abakh commented 3 years ago

The only warnings I see when compiling with --std=c99 are illegitimate warnings about functions being implicitly defined when used (when the headers are already included) I think I once checked why they happen and it was because of dirty interleaved preprocessor conditions in libc headers. I added a comment about it in makefile back then.

Of course I know that is standard. When I added --std=c99 it suddenly became non-existent, perhaps because of similar reasons as above. The math header was already there. So I added the definition as a workaround.

None of those problems arise when not including --std=c99 and both seem to be GNU's fault.

clausecker commented 3 years ago

Here's what I get (cc is clang):

$ make CC="cc --std=c99 -Wall -fno-common"                                                                                                                                                           
cc --std=c99 -Wall -fno-common jewels.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./jewels
In file included from jewels.c:22:
In file included from ./common.h:15:
./config.h:52:21: warning: redefinition of typedef 'byte' is a C11 feature [-Wtypedef-redefinition]
typedef signed char byte;
                    ^
jewels.c:21:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./common.h:15:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./config.h:52:21: note: unguarded header; consider using #ifdef guards or #pragma once
typedef signed char byte;
                    ^
1 warning generated.
cc --std=c99 -Wall -fno-common sudoku.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\"  -o ./sudoku
cc --std=c99 -Wall -fno-common mines.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./mines
cc --std=c99 -Wall -fno-common reversi.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\"  -o ./reversi
cc --std=c99 -Wall -fno-common checkers.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./checkers
cc --std=c99 -Wall -fno-common battleship.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./battleship
cc --std=c99 -Wall -fno-common rabbithole.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./rabbithole
cc --std=c99 -Wall -fno-common sos.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./sos
cc --std=c99 -Wall -fno-common pipes.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./pipes
In file included from pipes.c:21:
In file included from ./common.h:15:
./config.h:52:21: warning: redefinition of typedef 'byte' is a C11 feature [-Wtypedef-redefinition]
typedef signed char byte;
                    ^
pipes.c:20:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./common.h:15:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./config.h:52:21: note: unguarded header; consider using #ifdef guards or #pragma once
typedef signed char byte;
                    ^
1 warning generated.
cc --std=c99 -Wall -fno-common fifteen.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./fifteen
cc --std=c99 -Wall -fno-common memoblocks.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./memoblocks
cc --std=c99 -Wall -fno-common fisher.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./fisher
In file included from fisher.c:23:
In file included from ./common.h:15:
./config.h:52:21: warning: redefinition of typedef 'byte' is a C11 feature [-Wtypedef-redefinition]
typedef signed char byte;
                    ^
fisher.c:22:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./common.h:15:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./config.h:52:21: note: unguarded header; consider using #ifdef guards or #pragma once
typedef signed char byte;
                    ^
fisher.c:89:9: warning: unused variable 'x' [-Wunused-variable]
        byte y,x;
               ^
fisher.c:193:7: warning: unused variable 'y' [-Wunused-variable]
        byte y,x;
             ^
fisher.c:193:9: warning: unused variable 'x' [-Wunused-variable]
        byte y,x;
               ^
fisher.c:371:2: warning: unused label 'End' [-Wunused-label]
        End:
        ^~~~
5 warnings generated.
cc --std=c99 -Wall -fno-common muncher.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./muncher
In file included from muncher.c:21:
In file included from ./common.h:15:
./config.h:52:21: warning: redefinition of typedef 'byte' is a C11 feature [-Wtypedef-redefinition]
typedef signed char byte;
                    ^
muncher.c:20:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./common.h:15:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./config.h:52:21: note: unguarded header; consider using #ifdef guards or #pragma once
typedef signed char byte;
                    ^
1 warning generated.
cc --std=c99 -Wall -fno-common miketron.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./miketron
In file included from miketron.c:21:
In file included from ./common.h:15:
./config.h:52:21: warning: redefinition of typedef 'byte' is a C11 feature [-Wtypedef-redefinition]
typedef signed char byte;
                    ^
miketron.c:20:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./common.h:15:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./config.h:52:21: note: unguarded header; consider using #ifdef guards or #pragma once
typedef signed char byte;
                    ^
miketron.c:358:6: warning: unused variable 'prex' [-Wunused-variable]
        int prex,prey;
            ^
miketron.c:358:11: warning: unused variable 'prey' [-Wunused-variable]
        int prex,prey;
                 ^
miketron.c:360:12: warning: unused variable 'constant' [-Wunused-variable]
        const int constant=150*(80*24)/(len*wid);//that is added to score
                  ^
miketron.c:375:17: warning: variable 'input' is used uninitialized whenever 'for' loop exits because its condition is false [-Wsometimes-uninitialized]
                for(byte b= 0;b<6;++b){
                              ^~~
miketron.c:405:12: note: uninitialized use occurs here
                preinput=input;
                         ^~~~~
miketron.c:375:17: note: remove the condition if it is always true
                for(byte b= 0;b<6;++b){
                              ^~~
miketron.c:365:5: warning: variable 'input' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
        if(has_colors()){
           ^~~~~~~~~~~~
miketron.c:405:12: note: uninitialized use occurs here
                preinput=input;
                         ^~~~~
miketron.c:365:2: note: remove the 'if' if its condition is always true
        if(has_colors()){
        ^~~~~~~~~~~~~~~~
miketron.c:391:20: note: initialize the variable 'input' to silence this warning
        int preinput,input;
                          ^
                           = 0
6 warnings generated.
cc --std=c99 -Wall -fno-common redsquare.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./redsquare
redsquare.c:474:7: warning: unused variable 'result' [-Wunused-variable]
        char result[70];
             ^
1 warning generated.
cc --std=c99 -Wall -fno-common darrt.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\"  -o ./darrt
In file included from darrt.c:24:
In file included from ./common.h:15:
./config.h:52:21: warning: redefinition of typedef 'byte' is a C11 feature [-Wtypedef-redefinition]
typedef signed char byte;
                    ^
darrt.c:23:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./common.h:15:10: note: './config.h' included multiple times, additional include site here
#include "config.h"
         ^
./config.h:52:21: note: unguarded header; consider using #ifdef guards or #pragma once
typedef signed char byte;
                    ^
darrt.c:296:7: warning: unused variable 'y' [-Wunused-variable]
        byte y,x;
             ^
darrt.c:296:9: warning: unused variable 'x' [-Wunused-variable]
        byte y,x;
               ^
darrt.c:389:7: warning: unused variable 'n' [-Wunused-variable]
        byte n;
             ^
darrt.c:431:2: warning: unused label 'End' [-Wunused-label]
        End:
        ^~~~
5 warnings generated.
cc --std=c99 -Wall -fno-common snakeduel.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\"  -o ./snakeduel
snakeduel.c:483:7: warning: unused variable 'max_survival' [-Wunused-variable]
        long max_survival;
             ^
1 warning generated.
abakh commented 3 years ago

Those didn't show up in gcc. Are they fixed now?

clausecker commented 3 years ago

Looks better now. Now I only get unused variable warnings:

fuz@miso:/usr/home/fuz/src/repo/nbsdgames$ make CC="cc --std=c99 -Wall -fno-common" 2>&1 | less                                                                                                                                               
cc --std=c99 -Wall -fno-common jewels.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./jewels
cc --std=c99 -Wall -fno-common sudoku.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\"  -o ./sudoku
cc --std=c99 -Wall -fno-common mines.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./mines
cc --std=c99 -Wall -fno-common reversi.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\"  -o ./reversi
cc --std=c99 -Wall -fno-common checkers.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./checkers
cc --std=c99 -Wall -fno-common battleship.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./battleship
cc --std=c99 -Wall -fno-common rabbithole.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./rabbithole
cc --std=c99 -Wall -fno-common sos.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./sos
cc --std=c99 -Wall -fno-common pipes.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./pipes
cc --std=c99 -Wall -fno-common fifteen.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./fifteen
cc --std=c99 -Wall -fno-common memoblocks.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./memoblocks
cc --std=c99 -Wall -fno-common fisher.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./fisher
fisher.c:89:9: warning: unused variable 'x' [-Wunused-variable]
        byte y,x;
               ^
fisher.c:193:7: warning: unused variable 'y' [-Wunused-variable]
        byte y,x;
             ^
fisher.c:193:9: warning: unused variable 'x' [-Wunused-variable]
        byte y,x;
               ^
fisher.c:371:2: warning: unused label 'End' [-Wunused-label]
        End:
        ^~~~
4 warnings generated.
cc --std=c99 -Wall -fno-common muncher.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./muncher
cc --std=c99 -Wall -fno-common miketron.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./miketron
cc --std=c99 -Wall -fno-common redsquare.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\" -o ./redsquare
cc --std=c99 -Wall -fno-common darrt.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\"  -o ./darrt
cc --std=c99 -Wall -fno-common snakeduel.c  -lncurses -lm -O2 -pipe -Wno-unused-result -D SCORES_DIR=\"/var/games\"  -o ./snakeduel
snakeduel.c:483:7: warning: unused variable 'max_survival' [-Wunused-variable]
        long max_survival;
             ^
1 warning generated.
abakh commented 3 years ago

Did more changes. Fixed now?

clausecker commented 3 years ago

Looks fine now! Please make a release and then close this issue so I can update the port.

abakh commented 3 years ago

Done.

clausecker commented 3 years ago

Port update submitted in PR 257259.