For you
1
Name:
Anonymous
2012-01-12 14:20
What is the output of this program and why?
#include <stdio.h>
void f(void) {
printf("hax my anus\n");
fflush(stdout);
f();
}
int main(void) {
f();
return 0;
}
2
Name:
Anonymous
2012-01-12 14:21
It's undefined
3
Name:
Anonymous
2012-01-12 14:22
It prints "hax my anus\n" forever.
4
Name:
Anonymous
2012-01-12 14:23
>>2
No it's not. It's implementation defined.
5
Name:
Anonymous
2012-01-12 14:25
>>4
printf without format string
6
Name:
Anonymous
2012-01-12 14:27
>>5
So
"hax my anus\n" isn't a format string?
7
Name:
Anonymous
2012-01-12 14:27
8
Name:
Anonymous
2012-01-12 14:29
9
Name:
Anonymous
2012-01-12 14:30
>>8
Oh, you were joking? Get the fuck
back to /g/ .
10
Name:
Anonymous
2012-01-12 14:30
11
Name:
Anonymous
2012-01-12 14:32
>>9
No he does what they always do on /g/, they say some retarded shit, it gets pointed out and then they pretend they were just joking.
12
Name:
Anonymous
2012-01-12 14:33
>>3
On my machine it segfaults after a while.
13
Name:
Anonymous
2012-01-12 14:35
>>12
infinite recursion, much?
14
Name:
Anonymous
2012-01-12 14:37
>>12
Exactly, as I said in
>>2 it is undefined.
>>4-11
See above, jokes on you
15
Name:
Anonymous
2012-01-12 14:38
It's not undefined, it runs forever.
16
Name:
Anonymous
2012-01-12 14:38
>>15
No it doesn't, it crashes.
17
Name:
Anonymous
2012-01-12 14:39
When I compile with -O3 it doesn't segfault but when I don't it does.
18
Name:
Anonymous
2012-01-12 14:39
>>17
herf derf it's undefined
19
Name:
Anonymous
2012-01-12 14:39
>>16
If that's the case then your implementation of C is non-conformant.
20
Name:
Anonymous
2012-01-12 14:40
That program is well defined and will run forever on a C virtual machine.
21
Name:
Anonymous
2012-01-12 14:40
>>19
But it is
non-deterministic , therefore the behaviour is undefined.
Get back to /g/
22
Name:
Anonymous
2012-01-12 14:41
>>21
No it's completely deterministic, it runs forever.
23
Name:
Anonymous
2012-01-12 14:41
What exactly is undefined about it?
That you run out of stack space? Well there isn't any stack in C.
24
Name:
Anonymous
2012-01-12 14:42
>>20
| forever
Protip: Forever is longer than you think.
25
Name:
Anonymous
2012-01-12 14:42
26
Name:
Anonymous
2012-01-12 14:42
>>23
It's non-deterministic, i.e. it doesn't have an entry point and an exit point.
27
Name:
Anonymous
2012-01-12 14:45
It doesn't crash on my Turing machine, it runs forever.
28
Name:
Anonymous
2012-01-12 14:47
>>22
Forever is an abstract term how can it be deterministic?
29
Name:
Anonymous
2012-01-12 14:48
It runs forever, a valid optimization is
void f(void) {
while (1) {
printf("hax my anus\n");
fflush(stdout);
}
}
Which is why it won't crash on your machines when you compile it with GCC and use optimization (GCC does TCO).
30
Name:
Anonymous
2012-01-12 14:48
>>22
It can't be deterministic.
31
Name:
Anonymous
2012-01-12 14:49
>>29
It's still non-deterministic, therefore undefined. You cant prove that it will produce the same output on any machine that implements C correctly.
32
Name:
Anonymous
2012-01-12 14:49
The C program won't stop executing and will continue to print "hax my anus\n", on our feeble machines it will probably crash due to resource exhaustion.
33
Name:
Anonymous
2012-01-12 14:50
>>29
oh you,
inb4 mental midgets, toilet scrubing, no future in the 'real world'
34
Name:
Anonymous
2012-01-12 14:50
>>31
It's well defined, please cite from the C standard what causes the undefined behavior.
35
Name:
Anonymous
2012-01-12 14:51
>>22
prove that it runs forever.
36
Name:
Anonymous
2012-01-12 14:51
>>34
| C standard
I'm talking about determinism v. non-determinism here
Go back to /g/ asshole
37
Name:
Anonymous
2012-01-12 14:52
>>33
I don't know what Kodak would say about this one to be honest, his two great loves, "real world programming" and "the C standard collides".
38
Name:
Anonymous
2012-01-12 14:52
>>36
So you can't? I can tell you why, because it is well defined.
39
Name:
Anonymous
2012-01-12 14:53
>>38
Prove that it runs forever then, asswipe
40
Name:
Anonymous
2012-01-12 14:54
>36
| Please provide proof that something doesn't exist
That is not how things work, brah
Newer Posts