Live data from Hacker News

C implementation of Tic-Tac-Toe in a single call to printf

github.com

11–20 of 85 posts

Re: C implementation of Tic-Tac-Toe in a single call to printf

#11
I am afraid that the author has disqualified himself by publishing the source code before the judging of IOCCC 2020 is over. See catch 22 in the rules: "The judges STRONGLY prefer to not know who is submitting entries to the IOCCC."[1] Even the winners are asked not to publish the code until it is available on the IOCCC web site.[2]

[1] https://ioccc.org/2020/rules.txt [2] Personal communication

Re: C implementation of Tic-Tac-Toe in a single call to printf

#12
Relevant talk on the motivation for printf-programming:

https://www.usenix.org/conference/usenixsecurity15/technical....

Very interesting. Roughly, that the existence of Turing-complete functions within programs creates a fundamental vulnerability that even rigid control over the control flow of a program cannot avoid.

Re: C implementation of Tic-Tac-Toe in a single call to printf

#13
post #9

> %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…

I'd never heard of %n, but I use printf's return value (the number of bytes written) for this kind of purpose, so

  n = printf("%s: ", prefix);
  printf("%s\n", line1);
  printf("%*s%s\n", n, " ", line2);

Re: C implementation of Tic-Tac-Toe in a single call to printf

#15
post #11

I am afraid that the author has disqualified himself by publishing the source code before the judging of IOCCC 2020 is over. See catch 22 in the rules: "The judges STRONGLY prefer to not know who is submitting entries to the IOCCC."[1] Even the winners are asked not to publish the code until it is available on the IOCCC web site.[2] [1] https://ioccc.org/2020/rules.txt [2] Personal communication

‘Strongly prefer‘ != disqualification

Re: C implementation of Tic-Tac-Toe in a single call to printf

#16
post #7

Some advanced clickbait we have here.

Nah. Dennis Ritchie HATES him. Program like a pro with this one weird trick! You won't believe what happens! That's proper bait.

Hence advanced bait. printf() is called in a while loop, so it is hardly a single call.

Re: C implementation of Tic-Tac-Toe in a single call to printf

#17
This 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://nicholas.carlini.com/

Re: C implementation of Tic-Tac-Toe in a single call to printf

#19

This 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

#20

> %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?

Normally you'd use %n with input functions like scanf(), not printf().
Post reply on HN