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:56

>>1
Non-deterministic code, and also it will not produce the same output for all implementations of C, however "correct" or "incorrect" they are.

Name: Anonymous 2012-01-12 14:56

So proving or disproving this is like solving the halting problem for this program or something?

Name: Anonymous 2012-01-12 14:56

C99 6.5.2.2.11 Recursive function calls shall be permitted, both directly and indirectly through any chain of other functions.
Because C has no stack, it can theoretically run forever. In fact tail recursion optimizations are possible only because the C standard does not mention a stack.

Name: Anonymous 2012-01-12 14:56

>>41
That's wrong, if it crashes then your implementation of C is flawed and not really C.

Name: Anonymous 2012-01-12 14:56

Go back to /v/

Name: Anonymous 2012-01-12 14:57

using printf instead of puts for printing strings
IHBT

Name: Anonymous 2012-01-12 14:57

>>42
What a neat little troll.

Name: Anonymous 2012-01-12 14:58

>>43
See? It's well defined and does run forever.

Name: Anonymous 2012-01-12 14:58

>>44
I said so (ref. implementations of C, however "correct" or "incorrect" they [the implentations] are), but the code is still non-deterministic!

Name: Anonymous 2012-01-12 14:59

>>48
| does run forever.
Prove it

Name: Anonymous 2012-01-12 14:59

Okay I get it, /g/ doesn't know the standard so they now think it's undefined after you spammed the shit out of them about the undefined program. Very clever, go away now.

Name: Anonymous 2012-01-12 14:59

ITT people using  gnuc89 or gnuc99 and it seg faults

Name: Anonymous 2012-01-12 15:00

>>43
A side note: The stack isn't the limitation. Theoretically a stack could have infinitely space.

Name: Anonymous 2012-01-12 15:00

No. The standard assumes that the host environment has sufficient resources to store and execute the program code itself -- which means that things like stack overflows and static allocation failures cannot happen on the C abstract machine. The behavior of the program is thus well defined, it prints "hax my anus\n" ad infinitum.

You might argue that these assumptions aren't sound, but it would be absolutely silly in any other case. What if the environment has insufficient resources to load the program code, should we be able to catch and deal with a code allocation failure?

Name: Anonymous 2012-01-12 15:00

>>50
Okay, it doesn't call exit and it never returns, so it runs forever.

Name: Anonymous 2012-01-12 15:01

>>55
Nope, that is not proof. It is an indication, but not a formal proof.

Name: Anonymous 2012-01-12 15:02

>>56
Please cite from the C standard how it might exit then.

Name: Anonymous 2012-01-12 15:02

>>54
Defined, yes, but not deterministic. Also, unlimited resources is a false premise as you have just shown.

>>55
That is not a proof. What if the program is interrupted.

Name: Anonymous 2012-01-12 15:02

>>54
Damn what a neat fucking troll. I'm going to post this on /g/.

Name: Anonymous 2012-01-12 15:03

>>43
Damn, you must have the link to the standard bookmarked or something.

Name: Anonymous 2012-01-12 15:04

>>58
What do you mean deterministic? Do you even have a clue what you are talking about?

Name: Anonymous 2012-01-12 15:04

>>57
Signals

Name: Anonymous 2012-01-12 15:06

Name: Anonymous 2012-01-12 15:07

>>60
It costs money, he probably has it in a pdf on his computer.

Name: Anonymous 2012-01-12 15:07

>>63
This has nothing to do with a Turing machine. Do you know what the C abstract machine is?

Name: Anonymous 2012-01-12 15:07

HEY PROG RUN MY PROGRAM AND TELL ME THE OUTPUT


#MIPS
main:   li $v0,4
        la $a0,hax
        syscall
        j main
.data
        hax: .asciiz "hax my anus\n"

Name: Anonymous 2012-01-12 15:08

Where may I acquire one of these C abstract machines?

Name: Anonymous 2012-01-12 15:08

I run all my programs on the C abstract machine.

Name: Anonymous 2012-01-12 15:09

>>65
The point wasn't the turing machine, but that you may have different results for every run, there isn't a well-defined entry and exit point, which is a requirement for determinism, therefore the program is ultimately indeterministic.

Name: Anonymous 2012-01-12 15:10

>>67
abstract
You sure you know what that word means?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-12 15:11

I think this would be undefined behavior because you're flushing stdout twice. There could be crash because you're attempting to free() more memory that what you allocate.

Name: Anonymous 2012-01-12 15:11

Gentlemen, please, if you are from /g/ and have arrived to /prog/ this month, please leave, there is no sense in arguing about things like these. The answers to questions like these are defined by standards so there is an actual answer to the questions, there is little use arguing about them without a copy of the standard so if you don't have one, please leave this thread.

Thank you for listening.

Name: Anonymous 2012-01-12 15:11

>>69
You don't have any idea what you are talking about. Please go away, I'm not going to explain things to a child.

Name: Anonymous 2012-01-12 15:12

http://www.gowrikumar.com/c/
have some real what does this prog output riddles,
don't come back to /prog/ until you clear them

Name: Anonymous 2012-01-12 15:14

>>72
standard is li3k 550 pages
(least the copy I just downloaded from the interwebz)
Seriously you call yourself professional and you can't even memorize a measly 550 pages.
Toilet scrubbing boo-hoo.

Name: Anonymous 2012-01-12 15:14

>>71
Does flushing stdout twice cause undefined behavior? That I didn't know. About free I'm guessing that fflush somehow calls free?

Name: Anonymous 2012-01-12 15:15

>>73
| blabla I failed formal logic 101
Okay then

Name: Anonymous 2012-01-12 15:16

>>71
Doesn't say so in the standard!!

Go back to /g/

Name: Anonymous 2012-01-12 15:17

So this ten line program have you all wondering?
Which of you are actually programmers?

Name: Anonymous 2012-01-12 15:17

>>79
Kodak

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