From aae8bf1b8375f704821e86db8b0794399efc3dda Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 16 Oct 2023 07:27:55 -0700 Subject: [PATCH] Improve my fixes to 1984/decot To make it look more like the original but to still work with compilers without -traditional-cpp (which clang does not support) and other defects with clang (including one that was problematic in linux but not macOS) code that used macros had to be modified and used directly. But I removed the macros because of this. Now they are added back even though they are unused, just to give it a more authentic, original look. The thanks-for-fixes.md file was updated for this, both formatting and otherwise, but an unfortunate thing is that another entry was also modified in there. This is because I was aiming to just do format fixes in 1984 in one pull request to save time but then I came across this and decided to fix it and this should be in a single pull request. Something I noticed is that the fix for linux clang _appears_ to not be needed at least with clang 16.0.6 but what the difference is is just extra warnings. I cannot imagine I changed it just for that so I have left that change in in case there was a problem in earlier versions or something else I do not recall. It should be noted that without the change at least with clang 16.0.6 it appears to work just fine. It is unclear if it should be changed back but again as I can't imagine that I would have changed it just for warnings I think it's wiser not to. --- 1984/decot/README.md | 11 +++------ 1984/decot/decot.c | 5 +++++ thanks-for-fixes.md | 53 ++++++++++++++++++++++++++++---------------- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/1984/decot/README.md b/1984/decot/README.md index dce899d1e..58c8f4af8 100644 --- a/1984/decot/README.md +++ b/1984/decot/README.md @@ -1,7 +1,6 @@ # Second place award -Dave Decot - +Dave Decot ## To build: @@ -9,14 +8,12 @@ Dave Decot make all ``` - ## To run: ```sh ./decot ``` - ### Alternate code: To try the original code that requires `-traditional-cpp`: @@ -26,7 +23,6 @@ make alt ./decot.alt ``` - ## Judges' remarks: This program prints out a string of garbage. @@ -36,8 +32,8 @@ The judges also offer this one comment: understand remarks! ### Historical remarks: -Some new (in 1984) compilers disliked line 15 of the original source, so we changed it -from: +Some new (in 1984) compilers disliked line 15 of the original source, so we +changed it from: ```c for(signal=0;*k * x * __FILE__ *i;) do { @@ -49,7 +45,6 @@ to: for(signal=0;*k *x * __FILE__ *i;) do { ``` - To see what we mean look at the [original source file](decot.orig.c). diff --git a/1984/decot/decot.c b/1984/decot/decot.c index 2c4471f88..1c1e5e128 100644 --- a/1984/decot/decot.c +++ b/1984/decot/decot.c @@ -1,3 +1,8 @@ +#define x = +#define double(a,b) int +#define char k['a'] +#define union static struct + int b, k['a'] = {sizeof( int(*)()) diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index c32199d36..1aa705395 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -95,13 +95,25 @@ Scovell](https://web.archive.org/web/20070120220721/https://thomasscovell.com/ta ## [1984/decot](1984/decot/decot.c) ([README.md](1984/decot/README.md])) -Cody fixed this to not require `-traditional-cpp` which not all compilers -support (clang does not support it for example). Clang is also more strict about -the args' types in `main()` and this was also a problem that Cody fixed, making -it work with both clang and gcc - in macOS. It was then noticed that with clang -in linux it did not work so this had to be further fixed which Cody also did. -For the original code with the gcc fix (noted below), see the alternate code -section in the README.md file. +Cody fixed this to not require `-traditional-cpp` which some compilers like +clang do not support. Fixing `-traditional-cpp` is, as noted earlier, very +complicated, but we encourage you to look at the alternate code (which is the +original code with a minor modification made by the judges) and the fixed +code, to see what had to be done. + +Clang is also more strict about the type of args in `main()` and this was also a +problem that Cody fixed, making it work with both clang and gcc. + +These fixes worked fine in macOS but it turned out that in some cases with clang +in linux it did not work so this had to be further fixed which Cody also did. It +is no longer clear what the problem was as in fedora 38 with clang 16.0.6 the +only difference is it causes additional warnings but it seems to work just fine. +It seems unlikely that a fix was made just for warnings so it is presumed that +there was another problem so the change is kept in place. + +A note about the fix is that the `#define`d macros that were used still exist +but are not used; they are left in just to make it look more like the original +entry. Nevertheless they cannot be used. Originally Yusuke supplied a patch so that this entry would compile with gcc - but not clang - or at least some versions. @@ -109,26 +121,29 @@ but not clang - or at least some versions. ## [1984/mullender](1984/mullender/mullender.c) ([README.md](1984/mullender/README.md])) -Cody provided an alternate version which was an improved version from the judges -so that everyone can enjoy it with systems that are not VAX/PDP. We also refer you -to the [FAQ](faq.md) as there are some winning entries that also let one enjoy -it - with more to them of course! +Cody provided an alternate version, an improved version of the judges, so that +everyone can enjoy it with systems that are not VAX/PDP. We also refer you to +the [FAQ](faq.md) as there are some winning entries that also let one enjoy it - +with more to them of course! Cody also added the [gentab.c](1984/mullender/gentab.c) file, modified to -compile with modern systems, which the author noted in their remarks which Cody -also found. +compile with modern systems, which the author noted in their remarks (which Cody +also found). ## [1985/applin](1985/applin/applin.c) ([README.md](1985/applin/README.md])) -Yusuke provided a patch to get this to not crash and Cody fixed this to -work with macOS (it printed the string `H????` in a seemingly infinite loop, -each time printing another `?`). +Both Cody and Yusuke fixed this; Yusuke got this to not crash and Cody fixed it +to work with macOS. -The problem with the crash is that it destructively rewrites string literals but -with `strdup()` it's safe. +The crash was because it destructively rewrites string literals. However with +`strdup()` it's safe. -For macOS it's because there was no prototype for `execlp()` and macOS has +The problem with macOS is that although it didn't crash, it printed `H????` in a +seemingly infinite loop, each time printing another `?`, probably until it ran +out of memory. + +The fix for macOS is that there was no prototype for `execlp()` and macOS has problems with missing prototypes for some functions (this was also seen when Cody fixed [1984/anonymous](/1984/anonymous/anonymous.c) for macOS as well). Ironically this fix was discovered through linux!