Home > Back-end >  Don't know what was wrong
Don't know what was wrong

Time:11-12

Novice, want to make a compare the size of the program, the result is so, please explain

CodePudding user response:

If (a==b)

CodePudding user response:

Recommend "C traps and defects", may also run into other,

CodePudding user response:

Of C's biggest traps are not the equal sign, but operation priority, bit operations (including shift) priority is lower than the equal sign, x & amp; 1==1 is actually x & amp; (1==1), how the design can let a person want to cry, just like joke?
Another counter-intuitive design is * p + 1 and is not the same thing * p++ completely
Later K& R also admitted that some priority in book design was wrong ~ ~ ~

CodePudding user response:

reference 3 floor early play play nuclear response:
C the biggest trap, not the equal sign, but the operation priority, bit operations (including shift) priority is lower than the equal sign, x & amp; 1==1 is actually x & amp; (1==1), how the design can let a person want to cry, just like joke?
Another counter-intuitive design is * p + 1 and is not the same thing * p++ completely
Later K& R also admitted that some priority in book design was wrong ~ ~ ~


* p + 1 and * p++ I feel or very habits, bit operations & amp; And logical operations & amp; & As if the same priority, according to the
Arithmetic - shift - relationship (less than) is greater than or equal to - logic (and, or, not)
Some really easy to mix, unintuitive,
Like C # also inherited the operator precedence of C language,

CodePudding user response:

Correct design should be=the lowest priority, followed by the==, & lt; <> Priority should be like */

CodePudding user response:

refer to 6th floor early play big play nuclear response:
correct design should be=the lowest priority, followed by the==, & lt; <> Priority should be like */


Computer languages such as English, French, how much is reasonable, how many unreasonable composition, French is very to represent Numbers, the best out of a world language, grammar, vocabulary more to learn than English,

CodePudding user response:

refer to 7th floor ooolinux response:
Quote: refer to the sixth floor early play big play nuclear war reply:

Correct design should be=the lowest priority, followed by the==, & lt; <> Priority should be like */


Computer languages such as English, French, how much is reasonable, how many unreasonable composition, French is very to represent Numbers, the best out of a world language, grammar, vocabulary more to learn than English,


This is not easy or not problem, but the rationality problem, a computer language is not a natural language, there is a clear definition and the mathematical foundation, from the point of mathematical theory, an arithmetic is actually a special arithmetic operations, operations/shift operations as a result of the numerical, priority should be and arithmetic operations at the same level, and the relationship between the result of the operation is a Boolean type, and logical operations should be the same level, which is a priority should be higher than the relationship of calculations, and shift also should be more upward, and arithmetic, the same priority, and should not be below add and subtract the priority of (because the shift in math,),
In fact, the problem of C operator precedence has been proposed, Ritchie in 1982, and explains the problem, why his response & amp; | priority is lower than the==, because the original design of C when there is no logical operators, logical operations are replaced with an operation, so the priority of the bit operations is in the normal logical operation priority that level, then increase the logical operators, should improve & amp; | priority is higher than the==, but has accumulated a lot of code, there are a lot of the if (a==b & amp; C==d) this kind of writing, for the sake of compatibility, there is no change of priority order,

CodePudding user response:

refer to eight floor early play play nuclear response:
Quote: refer to 7th floor ooolinux response:

Quote: refer to the sixth floor early play big play nuclear war reply:

Correct design should be=the lowest priority, followed by the==, & lt; <> Priority should be like */


Computer languages such as English, French, how much is reasonable, how many unreasonable composition, French is very to represent Numbers, the best out of a world language, grammar, vocabulary more to learn than English,


This is not easy or not problem, but the rationality problem, a computer language is not a natural language, there is a clear definition and the mathematical foundation, from the point of mathematical theory, an arithmetic is actually a special arithmetic operations, operations/shift operations as a result of the numerical, priority should be and arithmetic operations at the same level, and the relationship between the result of the operation is a Boolean type, and logical operations should be the same level, which is a priority should be higher than the relationship of calculations, and shift also should be more upward, and arithmetic, the same priority, and should not be below add and subtract the priority of (because the shift in math,),
In fact, the problem of C operator precedence has been proposed, Ritchie in 1982, and explains the problem, why his response & amp; | priority is lower than the==, because the original design of C when there is no logical operators, logical operations are replaced with an operation, so the priority of the bit operations is in the normal logical operation priority that level, then increase the logical operators, should improve & amp; | priority is higher than the==, but has accumulated a lot of code, there are a lot of the if (a==b & amp; C==d) this kind of writing, for the sake of compatibility, there is no change of priority order,



Actually the C # or inherited C a lot of things,

CodePudding user response:

For reasons of code migration, C + +, C #, Java has inherited the operator priority order of the C ~ ~ ~

CodePudding user response:

earlier reference to the tenth floor to play big play nuclear response:
for reasons of code migration, C + +, C #, Java has inherited the operator priority order of the C ~ ~ ~


C as the influence of the language is too big,
  • Related