>>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:
Anonymous2012-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:
Anonymous2012-01-12 14:50
>>29
oh you,
inb4 mental midgets, toilet scrubing, no future in the 'real world'
Name:
Anonymous2012-01-12 14:50
>>31
It's well defined, please cite from the C standard what causes the undefined behavior.
>36
| Please provide proof that something doesn't exist
That is not how things work, brah
Name:
Anonymous2012-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:
Anonymous2012-01-12 14:56
So proving or disproving this is like solving the halting problem for this program or something?
Name:
Anonymous2012-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:
Anonymous2012-01-12 14:56
>>41
That's wrong, if it crashes then your implementation of C is flawed and not really C.
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:
Anonymous2012-01-12 14:59
ITT people using gnuc89 or gnuc99 and it seg faults
Name:
Anonymous2012-01-12 15:00
>>43
A side note: The stack isn't the limitation. Theoretically a stack could have infinitely space.
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:
Anonymous2012-01-12 15:00
>>50
Okay, it doesn't call exit and it never returns, so it runs forever.
Name:
Anonymous2012-01-12 15:01
>>55
Nope, that is not proof. It is an indication, but not a formal proof.
Name:
Anonymous2012-01-12 15:02
>>56
Please cite from the C standard how it might exit then.
Name:
Anonymous2012-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:
Anonymous2012-01-12 15:02
>>54
Damn what a neat fucking troll. I'm going to post this on /g/.
>>63
This has nothing to do with a Turing machine. Do you know what the C abstract machine is?
Name:
Anonymous2012-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:
Anonymous2012-01-12 15:08
Where may I acquire one of these C abstract machines?
Name:
Anonymous2012-01-12 15:08
I run all my programs on the C abstract machine.
Name:
Anonymous2012-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.
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.
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.
>>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:
Anonymous2012-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?
>>83
Actually this is a well defined program that doesn't rely on any compiler.
Name:
Anonymous2012-01-12 15:21
>>84
Yes it does, if it doesn't then your implementation of C is flawed.
Name:
Anonymous2012-01-12 15:22
It depends on OP's premise: Is he referring to the output he gets on his machine, or from a "correct" implementation of C? In the first case it relies on undefined behavior that ultimately results in a Segmentation fault. Clever troll. Now go back to /g/
>>76
I'm actually a Java Programmer, but anyways.....
Unless things have changes, fflush() itself is a (circular) linked list. When this function gets called, it will check against the "base". If the "base" is NULL, it will call malloc(). Otherwise it will do some kind of write().
Name:
Anonymous2012-01-12 15:24
>>91
Then your implementation of C is flawed get a conforming compiler.
Name:
Anonymous2012-01-12 15:24
>>89
inb4 IM USING A C VIRTUAL MACHINE NOT UR SHITTY COMPLIER
Name:
Anonymous2012-01-12 15:26
Now this is the first time I'm curious as to what Zhivago would say, I'm guessing it would something in line with >>54.
>>96
At least I have enough of an idea on how fflush() actually works to make a reasonable guess on the source of the crash you fucking toilet scrubber. Now shut up and go google something.
Again, you're stupid. And again, you have no possible future as a computer programmer.
>>101
You have an 'idea'
Now provide some evidance.
But I will abandon my 'computer programmer' aspirations and move onto World Domination as soon as I 1CC some lunatic touhou
>>102
Listen you little stupid fucker. Go read "The C Programming Language" by K & R. At the end of chapter 8, there is a programming excercise that asks you to implement fflush().
Now shut up and go scrub another toilet you fucking dumbass.
>>104
n1124 §7.19.5.3 If stream points to an output stream [...] the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file
>>114
Well, you seem to get your panties in a bundle when I call you on your stupidity. Why don't just give your lame a ego a rest, accept that fact that your entire schooling was a waste, and accept that fact you will more than likely not land any kind of programming job when you get out of school.
>>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:
Anonymous2012-01-12 16:11
Kodak, are your co-workers competent programmers or are some of them also mental midgets?
Name:
Anonymous2012-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:
Anonymous2012-01-12 16:20
anal sexual intercourse without any lubricant
Name:
Anonymous2012-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.
>>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:
Anonymous2012-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:
Anonymous2012-01-12 16:42
>>132
I don't know who is "told" but I am happy you found the standard agreeable.
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:
Anonymous2012-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:
Anonymous2012-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.
>>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:
Anonymous2012-01-12 17:19
>>138
| You should try getting your hands on a copy of the standard
Will do
Name:
Anonymous2012-01-12 17:25
>>130
Due to recursion optimization, it loops indefinately.
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:
Anonymous2012-01-13 5:02
>>142
So the program in >>1 is both well defined and deterministic, good to know.
>>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:
Anonymous2012-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.