"Teeth long Mouth" and "A + = A-= A *"

Source: Internet
Author: User

The story of the subject comes from the crosstalk "things": A says a word, and B says it upside down. For example, Party A says "table" and Party B says "sub table ". When Jia said "I have teeth in my mouth", B said "I have a mouth in my teeth" according to the agreed rules ". At this moment, the "baggage" immediately shakes and is full of support.
The reason is that "mouth in your teeth" is out of expectation, and people cannot imagine how "mouth in your teeth" can be ". However, on the other hand, we must admit that "I have a long mouth in my teeth" is quite syntactic-it is not because it breaks through the barriers of language standards, it is due to its absurd connotation-it describes a situation that is simply unimaginable and meaningless.
Crosstalk is the art of language, and programming is also the art of language. Coincidentally, in the C language, we can also say this kind of "Inner Teeth", which is called "undefined behavior" (UB ). I am afraid that the most famous UB is the expression "A + = A-= A * A" that I have been talking about for more than 20 years in "C program design", a self-proclaimed "mainstream teaching material" written by Tan haoqiang., this expression is a typical "inner mouth ". Why?
We all know that a programming language is a human-defined formal language, so the meaning of this language is also defined by humans. For example, the expression 1 + 1 requires a computer to obtain the value of 1 + 1. But what is the meaning of 1 + int_max (Note: int_max is a macro defined in limits. H, which indicates the maximum value that the int data type can represent on the compiler? Sorry, the C language does not specify what it means. This is the so-called ub. The meaning of the 1 + int_max statement is not stipulated in C language. In other words, no one knows what it means. So this is "Inner Teeth ".
Is there a basis? Yes. The C standard describes the "+" operation with the following sentence: if an predictional condition occurs during the evaluation of an expression (that is, if the result is not mathematically defined or not in the range of representable values for its type), the behavior is undefined.
The standard is always so hard to understand. The reason is simple. The standard is rigorous, and readability is never the first goal. So here I have to explain it in plain words. It means that when the expression is evaluated, if something unexpected happens, such as 1/0, This is not explained in mathematics, or the result is not within the range indicated by the corresponding type. (1 + int_max is the case where two int types of data are added to get an int type value, but now this value is beyond the int type expression range), then what does this expression mean? C language says it does not know.
So the problem is that you have written an expression like 1 + int_max, and you don't even know what the C language means. Do you know what you mean? You may think that you know, just as you think that you know what the meaning is, but it can only be an illusion, because no one knows what it should look like.
"A + = A-= A * A", which has been widely talked about for more than 20 years in the "mainstream textbooks", is also "Inner Teeth" because the C language stipulates: between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression.
This statement means that the value of the same data object can be changed at most once between two adjacent sequence points. A more common explanation is that, in ,,? : In an operation expression, the value of the same data object can be changed at most once. This is a basic rule that programmers must follow when writing expressions. The code that violates this rule is "Inner Teeth ". Because its behavior is not defined in C language, such code is wrong.
But some do not. One common view is that UB is not an error and compilation is not an error. This is tantamount to saying that "teeth are long" is a mistake, and "teeth are long Mouth" is not a mistake. This is undoubtedly superficial and absurd. If a programmer writes a C language that does not specify its meaning, then he thinks that he knows the meaning of the Code. Is it possible that it is correct?
Those who insist that UB is not an error often have a plausible reason, that is, the compiler does not report an error. But the problem is that the C language only requires the compiler to see the "teeth in the mouth" so that it must report an error, but does not require the compiler to see the "teeth in the mouth. This is like listening to the crosstalk and listening to the "mouth in your teeth". Everyone just smiles and no one will correct it out loud. Therefore, the compiler does not report errors and cannot prove that the code is correct, just
Int I;
Scanf ("% d", I );
Many compilers do not report the same crazy way of writing this code.
Scanf ("% d", I); many compilers give warnings for such code, "A + = A-= A * A" is also warned in some "smart" compilers, this is just like "Heartbeat in your teeth.
So the question goes back to the original starting point. Is the code of "A + = A-= A * A" Long mouth in your teeth meaningful? If you think that "your teeth are too long", then "A + = A-= A * A" is undoubtedly wrong. If you seriously think that it is not ridiculous to have a long mouth in your teeth, can you please give it to everyone?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.