Oddly enough I find that the #define macro soup detracts from the performance here. I was rather unimpressed at first because obfuscating C code by just #define'ing a bunch of code is a trivial and rather uninteresting way to write unreadable code. Of course you can make any arbitrary code look like a printf call with enough macros! But it's actually a lot more clever than that. I feel like this would be a lot more i…
One time, I had to maintain C code That somebody had #define'd to look like FORTRAN. It was impressive.
C implementation of Tic-Tac-Toe in a single call to printf
61–70 of 85 posts
Re: C implementation of Tic-Tac-Toe in a single call to printf
#62> We ab^H^Huse [the Turing-completeness of printf()] to implement a the logic of tic-tac-toe entirely within this one printf call (and a call to scanf() to read user input).
So it should be "one printf() and one scanf()."
Re: C implementation of Tic-Tac-Toe in a single call to printf
#63> in a single call to printf > while(*d) printf(fmt, arg) How's that a single call ?
Re: C implementation of Tic-Tac-Toe in a single call to printf
#64Earlier quoted context omitted.
Alas, it's technically difficult to get input from the user using printf.
If you’re willing to lose almost all portability, I think you could read a value from an I/O port, pass that to printf , use that as the field width for a string to print, count the character length of the resulting string using %n to move it into a variable, and then backspace over that to prevent the output from dirtying your output. You could only use the results in a subsequent call to printf , though. Of course,…
Re: C implementation of Tic-Tac-Toe in a single call to printf
#65Re: C implementation of Tic-Tac-Toe in a single call to printf
#66Earlier quoted context omitted.
One time, I had to maintain C code That somebody had #define'd to look like FORTRAN. It was impressive.
I've had to deal with code like that, only poorly mimicking Lisp instead: `#define unless(_x) if (!(_x))` etc... One of my favourite accidental features in Rust is that macros are so annoying and cryptic to write that people think twice before abusing them.
Re: C implementation of Tic-Tac-Toe in a single call to printf
#67In case you're wondering (like me) how you'd get input from printf(): > We ab^H^Huse [the Turing-completeness of printf()] to implement a the logic of tic-tac-toe entirely within this one printf call (and a call to scanf() to read user input). So it should be "one printf() and one scanf()."
Re: C implementation of Tic-Tac-Toe in a single call to printf
#68Oddly enough I find that the #define macro soup detracts from the performance here. I was rather unimpressed at first because obfuscating C code by just #define'ing a bunch of code is a trivial and rather uninteresting way to write unreadable code. Of course you can make any arbitrary code look like a printf call with enough macros! But it's actually a lot more clever than that. I feel like this would be a lot more i…
The reason he had to use macros is that the actual formatting string is huge and difficult to understand. In this case, macros really serve a useful purpose, instead of just obfuscating code.
Re: C implementation of Tic-Tac-Toe in a single call to printf
#69Oddly enough I find that the #define macro soup detracts from the performance here. I was rather unimpressed at first because obfuscating C code by just #define'ing a bunch of code is a trivial and rather uninteresting way to write unreadable code. Of course you can make any arbitrary code look like a printf call with enough macros! But it's actually a lot more clever than that. I feel like this would be a lot more i…
One time, I had to maintain C code That somebody had #define'd to look like FORTRAN. It was impressive.
E.g.
/usr/src/cmd/sh/mac.h:
#define IF if(
#define THEN ){
#define ELSE } else {
#define ELIF } else if (
#define FI ;}
#define BEGIN {
#define END }
#define SWITCH switch(
#define IN ){
#define ENDSW }
#define FOR for(
#define WHILE while(
[1] https://research.swtch.com/shmacroRe: C implementation of Tic-Tac-Toe in a single call to printf
#70Oddly enough I find that the #define macro soup detracts from the performance here. I was rather unimpressed at first because obfuscating C code by just #define'ing a bunch of code is a trivial and rather uninteresting way to write unreadable code. Of course you can make any arbitrary code look like a printf call with enough macros! But it's actually a lot more clever than that. I feel like this would be a lot more i…
One time, I had to maintain C code That somebody had #define'd to look like FORTRAN. It was impressive.