From 9941402291c4163d6f58d619e8626a4ab5211370 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Tue, 14 Mar 2023 07:35:19 -0700 Subject: [PATCH] Get 1986/holloway to compile with clang As I described in the README.md the problem was that clang is more strict about the second (also third but this is not used) arg type being char **. However changing its type to char ** and updating *s to be **s resulted in a core dump (segfault); and not doing that caused other problems. The fix was to do a char *t = s; and then update in the code the references to s to be t (including passing it to main()). This makes it compile and run successfully with both clang and gcc. --- 1986/holloway/README.md | 10 ++++++---- 1986/holloway/holloway.c | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/1986/holloway/README.md b/1986/holloway/README.md index 0ed6b1c52..398945184 100644 --- a/1986/holloway/README.md +++ b/1986/holloway/README.md @@ -10,10 +10,12 @@ USA make all -NOTE: we could not compile this entry under modern macOS but it will work -fine under linux. It likely fails to compile under macOS because its gcc is -actually just clang which is more strict about the type of the second -argument of main(). If you have gcc under macOS it might work just as well. +NOTE: Cody Boone Ferguson fixed this to compile with clang (it worked with gcc). +The problem was that clang is more strict about the type of second arg to +main(). However simply changing it to a `char **` and updating the `*s` to `**s` +caused a segfault. By adding a new variable, `char *t`, initialising it to `s` +and then using `t` instead of `s` it compiles and runs successfully under clang +and gcc. Thank you Cody for your assistance! ## Judges' comments: diff --git a/1986/holloway/holloway.c b/1986/holloway/holloway.c index e894200f0..2e438fb5a 100644 --- a/1986/holloway/holloway.c +++ b/1986/holloway/holloway.c @@ -11,7 +11,8 @@ long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L }; int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 }; -main(m1,s) char *s; { +main(m1,s) char **s; { + char *t = s; int a,b,c,d,o[k],n=(int)s; if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); } else switch(m1-=h){ @@ -27,7 +28,7 @@ main(m1,s) char *s; { if((b=n)>=e)for(b=g<