[asterisk-users] Single = sign and double == sign.What is the difference and when to use the two properly?
jon pounder
jonp at inline.net
Fri Jan 11 11:28:21 CST 2013
On 01/11/2013 12:20 PM, A J Stiles wrote:
I try to write comparisons as != where possible and then there is no
confusion and less mistakes possible.
Most compilers will warn on the example below now.
> On Friday 11 January 2013, penguin wrote:
>> quick question that leaves alittle confusion here. Im confused on the
>> difference or when to use the other if i have 1 = sign or 2 == signs .. so
>> If i had
>>
>> exten => _XXXX,1,answer()
>> same=> n,Set($[${a}==1]?true:false] <--double equal sign
>> same => n(true),Goto(main,s,1)
>> same=> n(false), Hangup()
>> would this be saying the same thing as above then?
>>
>> exten => _XXXX,answer()
>> same=> n,Set($[${a}=1]?true:false] <-- single equal sign
>>
>> in essence wouldn't i get the same result ? im confused on the double and
>> single equal sign and when to use the difference of the two. Would i get
>> the same result in both these expressions?
> Generally, one = sign means you're telling. Two == signs means you're asking.
>
> It's amusing (for sadists) to see ex-BASIC programmers trip up over this and
> write something like this:
>
> if (denominator = 0) {
> printf ("Can't divide by zero!\n");
> } else {
> answer = numerator / denominator
> };
>
> This will never print "Can't divide by zero!" because you are actually
> assigning a value to a variable right there in the conditional, and returning
> the assigned value. Since this is zero, the if() will fail and drop through
> to the else clause -- and then, just to confuse you, the program will crash
> with "Floating point exception" anyway.
>
More information about the asterisk-users
mailing list