> in a single call to printf > while(*d) printf(fmt, arg) How's that a single call ?
> How's that a single call syntactically it is. But it's not a very clear description. So how would you describe that single call location getting executed in a loop so everybody understands what is really meant? A single line of code is worse.
C implementation of Tic-Tac-Toe in a single call to printf
41–50 of 85 posts
Re: C implementation of Tic-Tac-Toe in a single call to printf
#42This is just crazy and I love it From a description on the author's website[1] of a Doom clone written in 13k of JavaScript. > Until recently all content on this website was research, and while writing papers can be fun, sometimes you just need to blow off a little steam. I think more companies should allow for their employees to have some plain old fun with no strings attached on a regular basis. [1] https://nichola…
>I think more companies should allow for their employees to have some plain old fun with no strings attached on a regular basis. Maybe we could call this additional 'holiday pay' or a longer 'weekend' and mandate it through law so that everyone benefits.
Re: C implementation of Tic-Tac-Toe in a single call to printf
#43Oddly 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…
Re: C implementation of Tic-Tac-Toe in a single call to printf
#44Re: C implementation of Tic-Tac-Toe in a single call to printf
#45It isn't really a "single call" to printf if it's in a while loop, is it?
There is a call to scanf in the middle of the arg #define
Re: C implementation of Tic-Tac-Toe in a single call to printf
#46Some advanced clickbait we have here.
Re: C implementation of Tic-Tac-Toe in a single call to printf
#47Earlier quoted context omitted.
On line 57: https://github.com/carlini/printf-tac-toe/blob/master/printt...
Ah, well spotted, thanks. I didn't think it was fair to call the title click bait just because it used a while loop to drive the calls to printf, but also including a scanf call is definitely not in the same spirit.
Re: C implementation of Tic-Tac-Toe in a single call to printf
#48> %n takes a pointer and writes (!!) the number of bytes printed so far. > Okay, everyone probably knows this. Let's get a bit more advanced. Ok, but I didn't know about that. What's the use?
One use is aligning outputs: char *prefix = "example"; char *line1 = "line 1"; char *line2 = "line 2"; printf("%s: %n%s\n", prefix, &n, line1); printf("%*s%s\n", n, "", line2); will output example: line 1 line 2 That’s a bit more robust than using strlen(s)+2 , where you have to keep that magic constant 2 in sync with ": ". Moving ": " to a variable and using strlen(s)+strlen(separator) would fix that, though (at the…
Re: C implementation of Tic-Tac-Toe in a single call to printf
#49Oddly 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.
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
#50Oddly 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…
https://gist.github.com/hugomg/73e91ebca7ced3c5c6f955e9e830b...