Merge pull request #280 from xexyl/1984-anonymous

Fix 1984/anonymous for macOS (clang?)
This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-04-04 11:30:32 -07:00
commit 7269e17179
3 files changed
+8 -44

No files matched your search

+6 -30
View File
@@ -11,37 +11,13 @@
./anonymous
NOTE: this entry will probably not work under macOS with the Apple chips (Intel
should be fine though we have no way to test this; if anyone can confirm whether
this will work under macOS with an Intel chip we'd appreciate if you let us
know). Although it will compile cleanly it will not print anything out. More
specifically, on modern systems one might need to specify `-m32` (though this
actually doesn't seem to be the case) but the Apple chips which are arm64 based
will not compile this entry:
ld: unknown/unsupported architecture name for: -arch armv4t
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [anonymous] Error 1
We were able to get it to work under linux on a 64-bit machine without
specifying `-m32`. However this will fail under the Apple chips because it is
arm64. If we specify `-arch i386` it will not compile:
Undefined symbols for architecture i386:
"_write", referenced from:
_read in anonymous-a2a56d.o
ld: symbol(s) not found for architecture i386
If we add to the CFLAGS `-include unistd.h` we will run into another problem:
anonymous.c:2:25: error: conflicting types for 'read'
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/unistd.h:472:10: note: previous declaration is here
ssize_t read(int, void *, size_t) __DARWIN_ALIAS_C(read);
^
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to work
under macOS. The fix was to prototype `read()` prior to being defined and not
using `int, int, int` as the entry does. Instead the second arg is a `void *`.
In the `read()` function which actually calls `write(2)` the `i` (which is the
`void *` has to be cast to an `int`. This solves the problem. Thank you Cody for
your assistance!
## Judges' comments:
+2 -2
View File
@@ -1,2 +1,2 @@
int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
int read(int,void*,int);i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(int j,void *i,int p){write(j/p+p,i---j,(int)i/(int)i);}
-12
View File
@@ -233,18 +233,6 @@ contact the author (unless you are the author! :-) ).
# 1984
## [1984/anonymous](1984/anonymous/anonymous.c) ([README.md](1984/anonymous/README.md))
## STATUS: doesn't work with some platforms - please help us fix
Although this works under linux it does not work under macOS: it prints nothing,
exiting 0.
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) added some notes about
this in the [README.md](1984/anonymous/README.md) file. Can you fix this? We
welcome your help!
# 1985