aap / pdp11

PDP-11 emulation
MIT License
54 stars 7 forks source link

Errors and warnings building on Mac #22

Open larsbrinkhoff opened 1 year ago

larsbrinkhoff commented 1 year ago

@eswenson1 discovered some errors and warnings building tv11 on Mac. Presumably this uses a recent version of clang we may not have encountered before.

/Library/Developer/CommandLineTools/usr/bin/make -C tools/tv11 tv11 CFLAGS=-O3
cc -O3   -c -o tv11.o tv11.c
tv11.c:97:1: warning: incompatible redeclaration of library function 'log' [-Wincompatible-library-redeclaration]
log (char *format, ...)
^
tv11.c:97:1: note: 'log' is a builtin with type 'double (double)'
1 warning generated.
cc -O3   -c -o tv.o tv.c
tv.c:287:18: warning: & has lower precedence than <; < will be evaluated first [-Wparentheses]
        curbuf = (*creg & BUFMASK < NUMFBUFFERS) ? &tv->buffers[*creg & BUFMASK] : nil;
                        ^~~~~~~~~~~~~~~~~~~~~~~
tv.c:287:18: note: place parentheses around the '<' expression to silence this warning
        curbuf = (*creg & BUFMASK < NUMFBUFFERS) ? &tv->buffers[*creg & BUFMASK] : nil;
                        ^ ~~~~~~~~~~~~~~~~~~~~~
tv.c:287:18: note: place parentheses around the & expression to evaluate it first
        curbuf = (*creg & BUFMASK < NUMFBUFFERS) ? &tv->buffers[*creg & BUFMASK] : nil;
                  ~~~~~~^~~~~~~~~
tv.c:505:2: error: call to undeclared function 'writen'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        writen(con->fd, largebuf, 3+8+WIDTH*HEIGHT/8);
        ^
tv.c:505:2: note: did you mean 'write'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:496:10: note: 'write' declared here
ssize_t  write(int __fd, const void * __buf, size_t __nbyte) __DARWIN_ALIAS_C(write);
         ^
tv.c:549:3: error: call to undeclared function 'writen'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                writen(tv->cons[tv->omap[osw]].fd, buf, 7);
                ^
tv.c:732:3: error: call to undeclared function 'writen'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                writen(con->fd, largebuf, 3+8+w*h*2);
                ^
1 warning and 3 errors generated.
larsbrinkhoff commented 1 year ago

I'm not sure about the warning about log. It looks like the standard function should only be declared if \ is included. Is clang in error here? Anyway, it's only a warning so the code is probably ok if the local log is declared early.

The three warnings about operator precedence look like actual concerns. The less-than expression is used as a mask, which is probably not intended.

writen is defined in util.c so it's just a matter of adding a declaration somewhere.

larsbrinkhoff commented 1 year ago

GCC versions 5.4 and 11.3 also complain about log, so I guess it really is a built in function per the C standard.