Make my fix to 1985/sicherman more like original
Yet again I was able to make it more like the original. This was done by
changing the 'C' macro to be 'c' and 'V' macro to 'v' so that I could
use 'C' and 'V' in main(). A minor downside is that the ')' at the end
of the line
* up.) (In the C Manual)*/
had to be commented out but since main() can now have both 'C' and 'V'
as parameters of the same type this seems well worth it.
Notice how the 'c' macro is now what the 'C' originally was, /b/! The
'V' to 'v' macro did not change its definition but now 'V' can be used.
Also the variable _ can be assigned to in main() it's just that the
subr() function cannot be called (previously both parts were commented
out).
Since C is now free we can have in subr() C be a char * which is what it
was originally.
Finally instead of having pairs of '"'s in subr() for the string
(assigned to C) we just escape the inner quotes.
The only difference from the original, besides the macro names and the
look it up in the C Manual part (I think in my tired head), is that some
of the macros have to be expanded and the subr() cannot be called. If I
can later on (that I am working on this is circumstantial, seeing an
untracked file when trying to clean up git status as it's too messy now)
figure out how to not have to expand the macros that would be great but
it's very possible that this is as close to the original as possible.
But since I said that before who knows.
This commit is contained in:
1 parent
578d96a00e
commit
e8eec65f9b
3 files changed
+43
-30
No files matched your search
@@ -40,7 +40,8 @@ include ../../var.mk
|
||||
#
|
||||
CSILENCE= -Wno-comment -Wno-deprecated-non-prototype -Wno-main -Wno-pedantic \
|
||||
-Wno-return-type -Wno-strict-prototypes -Wno-unused-parameter -Wno-implicit-int \
|
||||
-Wno-implicit-function-declaration -Wno-unused-value -Wno-multichar
|
||||
-Wno-implicit-function-declaration -Wno-unused-value -Wno-multichar \
|
||||
-Wno-uninitialized -Wno-unused-but-set-parameter
|
||||
|
||||
# Common C compiler warning flags
|
||||
#
|
||||
|
||||
@@ -2,25 +2,26 @@
|
||||
#define _C_C(_)('\b'b'\b'>=C_C>'\t'b'\n')
|
||||
#define C_C _|_
|
||||
#define b *
|
||||
#define C /**/
|
||||
#define V _C_C(
|
||||
#define c /b/
|
||||
#define v _C_C(
|
||||
char _,__;
|
||||
main(/*C,V)
|
||||
char **V;*/
|
||||
main(C,V)
|
||||
char **V;
|
||||
/* C program. (If you don't
|
||||
* understand it look it
|
||||
* up.) (In the C Manual*/)
|
||||
* up.) (In the C Manual)*/
|
||||
{
|
||||
char _,__;
|
||||
while (read(0,&__,1) & write((_=(_=~' '&__,/*/)),
|
||||
_C_,1)) _=/*/-('\b'b'\b'>=_|_>'\t'b'\n'))?__:__-_+
|
||||
'\b'b'\b'|((_-52)%('\b'b'\b'+~' '&'\t'b'\n')+1),1),
|
||||
&_,1))/*_=C-V+subr(&V)*/;
|
||||
&_,1))_=0/*C-*V+subr(&V)*/;
|
||||
}
|
||||
|
||||
subr(C)
|
||||
char *C;
|
||||
{
|
||||
"Lint says argument Manual isn't used." "What's that\
|
||||
C="Lint says \"argument Manual isn't used.\" What's that\
|
||||
mean?"; while (write((read(('"'-'/*"'/*"*/))?__:__-_+
|
||||
'\b'b'\b'|((_-52)%('\b'b'\b'+C_C_('\t'b'\n'))+1),1),&_,1));
|
||||
}
|
||||
+33
-22
@@ -375,7 +375,7 @@ then compare it to [sicherman.c](1985/sicherman/sicherman.c) for some good old
|
||||
C-fashioned fun (alternatively, see below explanation)!
|
||||
|
||||
Later on Cody improved the fix so that it looks much more like the [original
|
||||
entry](1985/sicherman/sicherman.c). He did this one more time and it's about as
|
||||
entry](1985/sicherman/sicherman.c). He did this two more times and it's about as
|
||||
close to the original as one can get without causing a compilation error.
|
||||
|
||||
To get this to all work the following changes were made. If you really want to
|
||||
@@ -387,27 +387,37 @@ make diff_orig_prog
|
||||
|
||||
and then read the following:
|
||||
|
||||
- The `C` macro was changed from `/b/` (which is `/*/`) to `/**/`. It could not
|
||||
be changed to use the token paste C preprocessor operator for reasons that will
|
||||
be explained below. No other macro had to be changed.
|
||||
- The `C` macro, `#define C /b/` was changed to `c`, so that in the function
|
||||
`subr()` we could assign to `C` (which there is a `char *`).
|
||||
- The code:
|
||||
|
||||
|
||||
C="Lint says "argument Manual isn't used." What's that
|
||||
mean?"; while (write((read(C_C('"'-'/*"'/*"*/))?__:__-_+
|
||||
mean?"; while (write((read(C_C('"'-'/*"'/*"*/))?__:__-_+
|
||||
'\b'b'\b'|((_-52)%('\b'b'\b'+C_C_('\t'b'\n'))+1),1),&_,1));
|
||||
|
||||
had to be changed to:
|
||||
|
||||
"Lint says argument Manual isn't used." "What's that\
|
||||
C="Lint says \"argument Manual isn't used.\" What's that\
|
||||
mean?"; while (write((read(('"'-'/*"'/*"*/))?__:__-_+
|
||||
'\b'b'\b'|((_-52)%('\b'b'\b'+C_C_('\t'b'\n'))+1),1),&_,1));
|
||||
|
||||
because C cannot be assigned to (see above) and because the string is broken
|
||||
up where it has symbols that are not strings.
|
||||
- In that function, `subr()`, although `C` could stay in the arg list, since it
|
||||
translates to `/**/` it cannot have a type. Nothing else had to change in the
|
||||
function except that the variables previously only in `main()`, `_` and `__`,
|
||||
had to be at the top of the file (in addition to the ones in `main()`).
|
||||
- The args to `main()` had to be commented out along with the code `up.) (In the
|
||||
C Manual)`.
|
||||
because of the missing `"` at the end of the line and the macro `C_C`
|
||||
(defined as `_|_`) had to be expanded. Can you figure out why the macro had
|
||||
to be expanded and yet it still works?
|
||||
|
||||
The `\"` had to be done to keep the `"`s there though the string could be
|
||||
broken up into multiple `"` pairs instead. Notice how the last line of code
|
||||
in that function is the same as before!
|
||||
|
||||
Notice how in that function `subr()`, `C` could still stay the same in the
|
||||
arg list (of `subr()`) since it is still a `char *C`! Since the `_` and `__`
|
||||
were added at file scope (in addition to where it already was in `main()`),
|
||||
the references to those variables could stay in the function.
|
||||
|
||||
- The code in main `up.) (In the C Manual)` had to be commented out though
|
||||
another option would have been to close the comment earlier, opened a new one,
|
||||
and added `int C;` instead.
|
||||
- The code in `main()` is the significant change as the macros had to be
|
||||
replaced for actual code so that instead of having the while loop condition as:
|
||||
|
||||
@@ -416,15 +426,16 @@ replaced for actual code so that instead of having the while loop condition as:
|
||||
|
||||
we have it as:
|
||||
|
||||
while (read(0,&__,1) & write((_=(_=~' '&__,/*/)),
|
||||
_C_,1)) _=/*/-('\b'b'\b'>=_|_>'\t'b'\n'))?__:__-_+
|
||||
'\b'b'\b'|((_-52)%('\b'b'\b'+~' '&'\t'b'\n')+1),1),
|
||||
&_,1))/*_=C-V+subr(&V)*/;
|
||||
while (read(0,&__,1) & write((_=(_=~' '&__,/*/)),
|
||||
_C_,1)) _=/*/-('\b'b'\b'>=_|_>'\t'b'\n'))?__:__-_+
|
||||
'\b'b'\b'|((_-52)%('\b'b'\b'+~' '&'\t'b'\n')+1),1),
|
||||
&_,1))_=0/*C-*V+subr(&V)*/;
|
||||
|
||||
- Finally, the function `subr()` cannot be called in the body of the `while()`
|
||||
loop as calling it will result in incorrect output, once you even get it to
|
||||
compile. See above where the loop has a body but the modification only has it
|
||||
commented out.
|
||||
- Finally, the function `subr()` cannot, as the above shows, be called in the
|
||||
body of the `while()` loop as calling it will result in incorrect output, once
|
||||
you even get it to compile (involving a cast, for instance, amongst other ways).
|
||||
Note though that we can still assign to the `\_` but we can't assign by calling
|
||||
the function.
|
||||
|
||||
|
||||
## [1986/hague](1986/hague/hague.c) ([README.md](1986/hague/README.md]))
|
||||
|
||||
Reference in new issue
Block a user