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 15:48

>>119
Go back to reddit while you're at it.

Name: Anonymous 2012-01-12 15:51

>>118
Kodak is so tsundere, concerned about my future~

Name: Anonymous 2012-01-12 15:55

>>122
You've consistently demonstrated that you're clueless. On top of it, you seem to have a "fragile ego". I don't know about any other programmers here, but I would be reluctant to forward your resume to any of the hiring managers at my job.

Name: Anonymous 2012-01-12 16:11

Kodak, are your co-workers competent programmers or are some of them also mental midgets?

Name: Anonymous 2012-01-12 16:15

>>124
Once in a while we get a few mental midgets. The bright ones end up getting reassigned to marketing or tech support. The rest get laid off.

Name: Anonymous 2012-01-12 16:20

anal sexual intercourse without any lubricant

Name: Anonymous 2012-01-12 16:28

5.1.2.3 states that

The least requirements on a conforming implementation are:
...
- At program termination, all data written to files shall be identical to the result that execution of the program according to the abstract semantics would have produced.
...


Since stdout is a FILE *, that means that any conforming C implementation must allow this program to loop until you interrupt it with a signal or something to that effect.

Name: Anonymous 2012-01-12 16:29

f()->
  io:format("hax my anus~n"),
  f().


WAT DOSE IT DEW?

Name: Anonymous 2012-01-12 16:30

>>127
But the loop doesn't terminate.

Name: Anonymous 2012-01-12 16:31

>>128
That depends on the Erlang(?) standard.

Name: Anonymous 2012-01-12 16:32

>>129
That is correct.

Name: Anonymous 2012-01-12 16:34

>>127
| At program termination, all data written to files shall be identical to the result that execution of the program according to the abstract semantics would have produced.
| At program termination
Fucking this. TOLD

Name: Anonymous 2012-01-12 16:36

>>129
But you are allowed to interrupt it with a signal, which is why I think implementations that send a SIGSEGV get away with still being conforming implementations, as far as the implementation is concerned it's not running out of stack space, it's just sending the program a signal.

The program is well defined according to the standard, you are allowed to flush an output stream as many times as you like.

Name: Anonymous 2012-01-12 16:42

>>132
I don't know who is "told" but I am happy you found the standard agreeable.

>>127
5.1.2.3 also states that

The least requirements on a conforming implementation are:
...
- The input and output dynamics of interactive devices shall take place as specified in 7.21.3. The intent of these requirements is that unbuffered and line-buffered output appear as soon as possible, to ensure that prompting messages actually appear prior to a program waiting for input.
...

So it must adhere to line-buffering, which is interesting, as printf in this case will send a new-line character in every iteration of the loop.

Name: Anonymous 2012-01-12 16:43

Every C program can be interrupted by a signal. Are all C programs inherently nondeterministic, since a given state can terminate in different ways?

Name: Anonymous 2012-01-12 16:46

>>135
I don't know to be honest, I'm still reading the standard, I'll see if I find some guarantees either way.

Name: Anonymous 2012-01-12 17:14

>>136
I would really like to discuss this.

Name: Anonymous 2012-01-12 17:18

>>137
You should try getting your hands on a copy of the standard and start reading or perhaps you should get the latest draft for free, it's supposed to be 99.9% compatible with the C11 standard, either way I'm having a lot of fun reading how C works (or is supposed to work). I'll get back to you if I find anything interesting.

Name: Anonymous 2012-01-12 17:19

>>138
| You should try getting your hands on a copy of the standard


Will do

Name: Anonymous 2012-01-12 17:25

>>130
Due to recursion optimization, it loops indefinately.

Name: Anonymous 2012-01-12 17:25

>>140
Good to know.

Name: Anonymous 2012-01-12 22:37

There has been egregious misuse of the term deterministic in this shitty /g/ infiltrated thread, I'm going to leave a definition here to clarify for posterity.

Deterministic algorithms can be defined in terms of a state machine, if the machine is deterministic, its current state determines what its next state will be; its course through the set of states is predetermined.

Sufficient for non-determinism:
Never Terminates: NO (States are still correctly determined)
Potentially interruptable: NO (The signal is considered input to the state machine)
Accepts user input: NO (as above)
Invokes undefined behavior: YES (Machine may draw numbers out of a hat to determine next state)
Invokes unspecified behavior: YES (The same machine may produce different output on identical runs)
Invokes implementation defined behavior: YES (In terms of the abstract machine, conforming implementations may produce different results on the same input)

Name: Anonymous 2012-01-13 5:02

>>142
So the program in >>1 is both well defined and deterministic, good to know.

Name: Anonymous 2012-01-13 7:37

>>142
Take a logic class or go back to /g/

Name: Anonymous 2012-01-13 12:44

>>142
Invokes implementation defined behavior: YES (In terms of the abstract machine, conforming implementations may produce different results on the same input)
Fuck off, faggot. GNU C is the true C.

Name: Anonymous 2012-01-13 12:51

If it was deterministic, then it wouldn't need the preprocessor. However, C does need a preprocessor, so like... Oh geeze, never mind. Go scrub another toilet you mental midget.

Name: Anonymous 2012-01-13 13:06

>>146
This

It is non-deterministic

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List