diff --git a/1998/schweikh2/.gitignore b/1998/schweikh2/.gitignore index 01b476714..85e3bc2d7 100644 --- a/1998/schweikh2/.gitignore +++ b/1998/schweikh2/.gitignore @@ -1,2 +1 @@ schweikh2 -schweikh2.alt diff --git a/1998/schweikh2/Makefile b/1998/schweikh2/Makefile index 09ecf9dcb..d0ebca79b 100644 --- a/1998/schweikh2/Makefile +++ b/1998/schweikh2/Makefile @@ -111,8 +111,8 @@ OBJ= ${PROG}.o DATA= TARGET= ${PROG} # -ALT_OBJ= ${PROG}.alt.o -ALT_TARGET= ${PROG}.alt +ALT_OBJ= +ALT_TARGET= # FORCE use of -trigraphs # diff --git a/1998/schweikh2/README.md b/1998/schweikh2/README.md index a325a9f71..a28393935 100644 --- a/1998/schweikh2/README.md +++ b/1998/schweikh2/README.md @@ -14,10 +14,6 @@ Germany make all ``` -NOTE: Almost every compiler is supposed to be able to accept the code in -[schweikh2.c](schweikh2.c); try compiling [schweikh2.alt.c](schweikh2.alt.c]) to -see if your compiler is fully standard-compliant. - ## To run: @@ -57,17 +53,19 @@ What happens if you don't put in any number like the below? Run the program with a small argument, like 5 or 10, several times. Are the results different? Why? -Some non-gcc compilers that are not fully ANSI standard do not compile this -entry correctly. +### Historical remarks: + +At the time of judging, some non-gcc compilers that were not fully ANSI standard +did not compile this entry correctly. At the time this hint file was written, some gcc and egcs implementations ran into problem when building the original entry: ```sh -make schweikh2.alt +make schweikh2 ``` -This program often will produce an error of the form: +This program often produced an error of the form: ``` gcc -ansi schweikh2.alt.c -o schweikh2.alt @@ -102,7 +100,7 @@ and the lone `"` after the `#.file` line results in an assembler syntax error. In some cases one must compile using `gcc -g`: ```sh -make schweikh2.alt CFLAGS=-g +make schweikh2 CFLAGS=-g ``` to trigger this error. @@ -111,19 +109,32 @@ And with the proper text beyond the `\012`, it may be possible to have all kinds of fun adding `inline assembly` via `#line` directives. :-) For extra credit: -If your compiler has this bug, transform the line in the C -program to inject assembly instructions in such a way that -the program will compile. +If your compiler had this bug, you could transform the line in the C program to +inject assembly instructions in such a way that the program would compile. -If you are able to do the above, try adding assembly instructions -so that it will compile, execute and do something interesting. +If you were able to do the above, you could try adding assembly instructions so +that it will compile, execute and do something interesting. -If you succeed in doing this (especially on FreeBSD, Linux or SPARC), -email the author for a free pat on the back. +If you succeeded in doing this (especially on FreeBSD, Linux or SPARC), +you could have emailed the author for a free pat on the back (and maybe you +still can :-) ). NOTE: the author submitted the program as `yarng` so when trying the examples below change `yarng` to `./schweikh2`. +However in 2023 it was observed that it is gcc that has a problem with the +compilation of the _modified_ program, giving an internal compiler error: + +``` +:10:16: warning: type defaults to 'int' in declaration of 'zero' [-Wimplicit-int] +: In function 'main': +:12:1: warning: missing terminating " character +:12:19: internal compiler error: invalid built-in macro "__FILE__" +``` + +so the string `"01\015"` was changed to `ONE(O(1,1,2,6,0,6))` and now it works +with both clang and gcc. + ## Author's remarks: ### What this program does diff --git a/1998/schweikh2/schweikh2.alt.c b/1998/schweikh2/schweikh2.alt.c deleted file mode 100644 index 324d51ff5..000000000 --- a/1998/schweikh2/schweikh2.alt.c +++ /dev/null @@ -1,20 +0,0 @@ -#define _POSIX_SOURCE /* you are not supposed to understand this */ -#define O(OOO,OO0,O00,O0O,OO,O0)\0##O0O%:%:OO\0##O0%:%:OOO\0##OO0%:%:O00 -#include -static volatile sig_atomic_t One; -#include -#include -#define Zero(NULL)#NULL -#define ONE(One) Zero(One) -int - -??=line 10 ONE(O(1,1,2,6,0,6)) -main (register zero, char **ONE) -%: -<% switch (sizeof __FILE__ < zero) case 1: return One /= zero; -{ auto one = zero = atoi (ONE<:zero-1:>); -do for (one += alarm (One |= (signal (__LINE__, (void(*)(register))main) -!= SIG_ERR)); One; ++one); -while (zero -= write (1, __FILE__+(one&1), 1)); -return write (1, 1+__FILE__+1, 1) != 1; -%>} diff --git a/1998/schweikh2/schweikh2.c b/1998/schweikh2/schweikh2.c index 283b25694..324d51ff5 100644 --- a/1998/schweikh2/schweikh2.c +++ b/1998/schweikh2/schweikh2.c @@ -8,7 +8,7 @@ static volatile sig_atomic_t One; #define ONE(One) Zero(One) int -#line 10 "01\015" +??=line 10 ONE(O(1,1,2,6,0,6)) main (register zero, char **ONE) %: <% switch (sizeof __FILE__ < zero) case 1: return One /= zero; diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index b0006d9d0..a12d4c878 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -740,6 +740,20 @@ Additionally Cody provided an alternate version for macOS. See the README.md file for details on the alternate version. +## [1998/schweikh2](1998/schweikh2/schweikh2.c) ([README.md](1998/schweikh2/README.md])) + +Cody fixed the code to not trigger an internal compiler error in gcc: + +``` +:10:16: warning: type defaults to 'int' in declaration of 'zero' [-Wimplicit-int] +: In function 'main': +:12:1: warning: missing terminating " character +:12:19: internal compiler error: invalid built-in macro "__FILE__" +``` + +The string `"01\015"` had to be changed to `ONE(O(1,1,2,6,0,6))`. + + ## [2000/anderson](2000/anderson/anderson.c) ([README.md](2000/anderson/README.md])) Cody changed this entry to use `fgets()` instead of `gets()` to make it safer