compound-assignment

what *p1 ^= *p2; does in c

做~自己de王妃 提交于 2021-02-05 12:15:15
问题 In C what does this statement do? *p1 ^= *p2; p1 and p2 are char pointers pointing to two different address of a char array. I know about ^ operator is XOR. 回答1: It should probably be easier to understand if you see it this way instead: char c1 = *p1; char c2 = *p2; c1 = c1 ^ c2; *p1 = c1; That's basically what the code you show is doing. This of course relies on you knowing how exclusive or actually works, and know about pointer dereferencing too. 回答2: This *p1 ^= *p2; is the compound

Lua operators, why isn't +=, -= and so on defined?

非 Y 不嫁゛ 提交于 2019-12-29 04:28:09
问题 This is a question I've been mildly irritated about for some time and just never got around to search the answer to. However I thought I might at least ask the question and perhaps someone can explain. Basically many languages I've worked in utilize syntactic sugar to write (using syntax from C++): int main() { int a = 2; a += 3; // a=a+3 } while in lua the += is not defined, so I would have to write a=a+3 , which again is all about syntactical sugar. when using a more "meaningful" variable

Shortcut “or-assignment” (|=) operator in Java

拟墨画扇 提交于 2019-12-27 11:04:32
问题 I have a long set of comparisons to do in Java, and I'd like to know if one or more of them come out as true. The string of comparisons was long and difficult to read, so I broke it up for readability, and automatically went to use a shortcut operator |= rather than negativeValue = negativeValue || boolean . boolean negativeValue = false; negativeValue |= (defaultStock < 0); negativeValue |= (defaultWholesale < 0); negativeValue |= (defaultRetail < 0); negativeValue |= (defaultDelivery < 0);

Why is this assignment ambiguous?

空扰寡人 提交于 2019-12-24 03:23:57
问题 Please note that this question is not about how to change the code below to make it work; rather, I am looking for some insight on why a compiler would find this assignment ambiguous: entity assignment_to_aggregates is end; architecture example of assignment_to_aggregates is type vowel_type is (a, e, i, o, u); type consonant_type is (b, c, d, f, g); type vowel_consonant_pair is record vowel: vowel_type; consonant: consonant_type; end record; signal my_vowel: vowel_type; signal my_consonant:

Addition assignment += behavior in expression

廉价感情. 提交于 2019-12-20 08:33:36
问题 Recently I came across this question: Assignment operator chain understanding. While answering this question I started doubting my own understanding of the behavior of the addition assignment operator += or any other operator= ( &= , *= , /= , etc.). My question is, when is the variable a in the expressions below updated in place, so that its changed value is reflected in other places in the expression during evaluation, and what is the logic behind it? Please take a look at following two

Addition assignment += behavior in expression

ε祈祈猫儿з 提交于 2019-12-20 08:32:24
问题 Recently I came across this question: Assignment operator chain understanding. While answering this question I started doubting my own understanding of the behavior of the addition assignment operator += or any other operator= ( &= , *= , /= , etc.). My question is, when is the variable a in the expressions below updated in place, so that its changed value is reflected in other places in the expression during evaluation, and what is the logic behind it? Please take a look at following two

Shortcut “or-assignment” (|=) operator in Java

安稳与你 提交于 2019-12-20 06:06:53
问题 I have a long set of comparisons to do in Java, and I'd like to know if one or more of them come out as true. The string of comparisons was long and difficult to read, so I broke it up for readability, and automatically went to use a shortcut operator |= rather than negativeValue = negativeValue || boolean . boolean negativeValue = false; negativeValue |= (defaultStock < 0); negativeValue |= (defaultWholesale < 0); negativeValue |= (defaultRetail < 0); negativeValue |= (defaultDelivery < 0);

Shortcut “or-assignment” (|=) operator in Java

前提是你 提交于 2019-12-20 06:06:48
问题 I have a long set of comparisons to do in Java, and I'd like to know if one or more of them come out as true. The string of comparisons was long and difficult to read, so I broke it up for readability, and automatically went to use a shortcut operator |= rather than negativeValue = negativeValue || boolean . boolean negativeValue = false; negativeValue |= (defaultStock < 0); negativeValue |= (defaultWholesale < 0); negativeValue |= (defaultRetail < 0); negativeValue |= (defaultDelivery < 0);

Sequence point within assignment operators

末鹿安然 提交于 2019-12-19 10:08:28
问题 Let's just take for example the specific compound assignment operator ^= . This stackoverflow page says modification of the left operand may have not been done after the evaluation of ^= , and thus making the code a ^= b ^= a ^= b undefined behaivor. But this does not seem to be the case. The standard says in 5.17 [expr.ass] that In all cases, the assignment is sequenced after the value computation of the right and left operands, and before the value computation of the assignment expression.

Why are there no ||= or &&= operators in C#?

心不动则不痛 提交于 2019-12-17 16:34:04
问题 We have equivalent assignment operators for all Logical operators, Shift operators, Additive operators and all Multiplicative operators. Why did the logical operators get left out? Is there a good technical reason why it is hard? 回答1: Why did the logical operators get left out? Is there a good technical reason why it is hard? They didn't . You can do &= or |= or ^= if you want. bool b1 = false; bool b2 = true; b1 |= b2; // means b1 = b1 | b2 The || and && operators do not have a compound form