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

Why Why

Name: why 2010-10-29 14:11

int i=5;
i = ++i;
print(i);//prints 6

int i=5;
i = i++;
print(i);//prints 6

int i = 5;
i = i++ + ++i;
print(i);//prints 11?...........NO ITS 12. WHY

Name: Anonymous 2010-10-29 14:20

You're an idiot. Read all of the following:
* Structure and interpretation of Code Tags
* http://www.wikihow.com/Use-English-Punctuation-Correctly
* K&R

Name: Anonymous 2010-10-29 14:23

because it's undefined behaviour.
(here prints 13)

Name: Anonymous 2010-10-29 14:30

I'll give you two out of ten for being so obvious it's almost insulting in itself.

Name: Anonymous 2010-10-29 19:08

What the hell language even is that? IHBT

Name: Anonymous 2010-10-29 20:43

The behaviour of i = i++ + ++i; is undefined? Really? Wow, what a huge piece of shit of a language they have there. This expression should expand to:


(+ (let ((k i))
        (set! i (+ i 1)) k)
   (begin (set! i (+ i 1))
          i))


which will return 12. With Racket it's easy to understand why: you evaluate subexpressions from left to right. The first argument to + does return the original i (5), but it modifies i before the second argument is evaluated, which ends up returning the original i incremented twice.

So, what can we learn from this? Side effects are evil. Use functional programming.

Name: Anonymous 2010-10-29 21:02

>>6
Or just don't modify an object twice between sequence points.

Name: Anonymous 2010-10-29 22:33

I can't wait fot lambdas to be standard Sepples.

Name: Anonymous 2010-10-29 23:23

I can't wait fot Sepples to be standard lambdas.

Name: Anonymous 2010-10-30 2:03

I can't wait fot standard lambdas to be Sepples.

Name: Anonymous 2010-10-30 7:14

>>6
Nowhere in the C standard does it say that the order of evaluation should be left-to-right. Rightly so: it allows programmers to follow the mathematical conventions for operator precedence in infix notation without having to use fucktons of parentheses.

Name: Anonymous 2010-10-30 7:53

>>6
Scheme doesn't specify the order of evaluation of sub expressions either. This gives freedom to the implementor of where to put intermediate values.

What a stupid thing to bash a language for. When would you ever do i = i++ + ++i; anyway?

Name: Anonymous 2010-10-30 9:30

>>6
Your reasoning only shows that you know nothing of what that sequence of machine instructions is produced for that expression.

Name: Anonymous 2010-10-30 9:47

>>13
Not necessarily. For instance, >>6 is also showing me that Lisp programmers are nitwits.

Name: Anonymous 2010-10-30 17:42

••

Name: Anonymous 2011-02-03 4:28

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