Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

For you

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;
}

Name: Anonymous 2012-01-12 14:21

It's undefined

Name: Anonymous 2012-01-12 14:22

It prints "hax my anus\n" forever.

Name: Anonymous 2012-01-12 14:23

>>2
No it's not. It's implementation defined.

Name: Anonymous 2012-01-12 14:25

>>4
printf without format string

Name: Anonymous 2012-01-12 14:27

>>5
So "hax my anus\n" isn't a format string?

Name: Anonymous 2012-01-12 14:27

>>5
Look again.

Name: Anonymous 2012-01-12 14:29

>>4-7
No sense of humor

Name: Anonymous 2012-01-12 14:30

>>8
Oh, you were joking? Get the fuck back to /g/.

Name: Anonymous 2012-01-12 14:30

>>9
Go back to /g/

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.

Name: Anonymous 2012-01-12 14:33

>>3
On my machine it segfaults after a while.

Name: Anonymous 2012-01-12 14:35

>>12
infinite recursion, much?

Name: Anonymous 2012-01-12 14:37

>>12
Exactly, as I said in >>2 it is undefined.

>>4-11
See above, jokes on you

Name: Anonymous 2012-01-12 14:38

It's not undefined, it runs forever.

Name: Anonymous 2012-01-12 14:38

>>15
No it doesn't, it crashes.

Name: Anonymous 2012-01-12 14:39

When I compile with -O3 it doesn't segfault but when I don't it does.

Name: Anonymous 2012-01-12 14:39

>>17
herf derf it's undefined

Name: Anonymous 2012-01-12 14:39

>>16
If that's the case then your implementation of C is non-conformant.

Name: Anonymous 2012-01-12 14:40

That program is well defined and will run forever on a C virtual machine.

Name: Anonymous 2012-01-12 14:40

>>19
But it is non-deterministic, therefore the behaviour is undefined.

Get back to /g/

Name: Anonymous 2012-01-12 14:41

>>21
No it's completely deterministic, it runs forever.

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.

Name: Anonymous 2012-01-12 14:42

>>20
| forever

Protip: Forever is longer than you think.

Name: Anonymous 2012-01-12 14:42

>>1
It's undecidable.

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.

Name: Anonymous 2012-01-12 14:45

It doesn't crash on my Turing machine, it runs forever.

Name: Anonymous 2012-01-12 14:47

>>22
Forever is an abstract term how can it be deterministic?

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).

Name: Anonymous 2012-01-12 14:48

>>22
It can't be deterministic.

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.

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.

Name: Anonymous 2012-01-12 14:50

>>29
oh you,
inb4 mental midgets, toilet scrubing, no future in the 'real world'

Name: Anonymous 2012-01-12 14:50

>>31
It's well defined, please cite from the C standard what causes the undefined behavior.

Name: Anonymous 2012-01-12 14:51

>>22
prove that it runs forever.

Name: Anonymous 2012-01-12 14:51

>>34
| C standard
I'm talking about determinism v. non-determinism here

Go back to /g/ asshole

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".

Name: Anonymous 2012-01-12 14:52

>>36
So you can't? I can tell you why, because it is well defined.

Name: Anonymous 2012-01-12 14:53

>>38
Prove that it runs forever then, asswipe

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
Don't change these.
Name: Email:
Entire Thread Thread List