From f444622706b66bf6dc65184257becffbe122187b Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Tue, 4 Apr 2023 06:38:42 -0700 Subject: [PATCH] Fix 1984/anonymous for macOS (clang?) This one was also fun. By chance I noticed the '{' next to the read() function. Easy enough to miss when very tired. Anyway I had to prototype that function as 'int read(int, void *, int)' and then in that function, in the call to write(2), cast 'i' (which is the void *) to int. This fixes the problem and now it works with macOS and linux. Removed this entry from bugs.md. --- 1984/anonymous/README.md | 36 ++++++------------------------------ 1984/anonymous/anonymous.c | 4 ++-- bugs.md | 12 ------------ 3 files changed, 8 insertions(+), 44 deletions(-) diff --git a/1984/anonymous/README.md b/1984/anonymous/README.md index 2ceeef704..cdc6e42c5 100644 --- a/1984/anonymous/README.md +++ b/1984/anonymous/README.md @@ -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: diff --git a/1984/anonymous/anonymous.c b/1984/anonymous/anonymous.c index a8681d1e5..8deda1980 100644 --- a/1984/anonymous/anonymous.c +++ b/1984/anonymous/anonymous.c @@ -1,2 +1,2 @@ -int i;main(){for(;i["]