Comparing function return value in C
1
Name:
Anonymous
2011-05-02 13:10
I was making a program and I noticed that doing
if ((j = function()) == 20)
and
if (function() == 20)
behaved differently. Why is this? What's the difference between one and the other? The first one (the one that has a variable with the function return value) behaved as I thought it would, which is comparing the function return value with the constant. I don't know what the other one does. Thanks.
2
Name:
Anonymous
2011-05-02 13:32
cretin
3
Name:
Anonymous
2011-05-02 13:36
>>2
C is the first letter of cretin.
4
Name:
Anonymous
2011-05-02 13:36
5
Name:
Anonymous
2011-05-02 13:37
They are the same except that j will be assigned a value in one case but not the other.
If you saw different behavior, then it's possible that function() has some static state and you get a different result each time you call it.
6
Name:
Anonymous
2011-05-02 13:39
>>5
And this is why mutable state is considered harmful.
7
Name:
nambla_dot_org_rules_you
2011-05-02 15:29
>>6
Because it's a side effect. Side effects are considered unholy in the jews of your jewish trained mathematicians that write code for a living.
8
Name:
Anonymous
2011-05-02 15:30
* in the eyes of your jewish trained mathematicians*
9
Name:
Anonymous
2011-05-02 15:56
>>6-7
I'm not sure which of you I hate more.
10
Name:
Anonymous
2011-05-02 16:20
ONE WORD THE IMPLICIT COERCION OF NUMBER TYPES THREAD OVER
11
Name:
nambla_dot_org_rules_you
2011-05-02 16:29
>>10
C has a number type? Is this an extension of the primitive types?
12
Name:
Anonymous
2011-05-02 17:45
>>11
Yes, yes he did definitely say 'number type', and not 'number types'.
Anyway the proper standardese is arithmetic types.
13
Name:
Anonymous
2011-05-02 18:44
>>10
Wow, you might be right!
Newer Posts