Fix internal gcc error in 1998/schweikh2
(Note that it used to be that some compilers had a problem with the
original source but now some compilers have a problem with the C
pre-processed code and in particular with the #line macro and this
commit addresses this problem.)
A funny problem occurred when compiling with gcc: 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__"
It now works with clang and gcc just as well. The alt source file was
removed as there is no need for it now. The fix was quite simple. The
string '"01\015"' had to be replaced with 'ONE(O(1,1,2,6,0,6))' and this
was actually what was in the original code in the archive and in the alt
code (which was removed as there is no need for it now though it
differed slightly from what is in the archive).
The trigraph was restored as the Makefile already had the -trigraphs
option forced in CFLAGS.
Note that the README.md file has had the judges' remarks changed in such
a way that there is a historical note as at the time of judging it was
the original code that had a problem with some compilers whereas now
some compilers have a problem with the modified code (or C pre-processed
code). These details are put in a new subsection 'Historical remarks'.
This commit is contained in:
1 parent
5daa925803
commit
2028d9c0b3
6 files changed
+44
-40
No files matched your search
@@ -1,2 +1 @@
|
||||
schweikh2
|
||||
schweikh2.alt
|
||||
@@ -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
|
||||
#
|
||||
|
||||
+27
-16
@@ -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
|
||||
|
||||
@@ -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<signal.h>
|
||||
static volatile sig_atomic_t One;
|
||||
#include<stdlib.h>
|
||||
#include<unistd.h>
|
||||
#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;
|
||||
%>}
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user