The language characteristics of the compilation system

zhaozj2021-02-16  90

Different compilation environments (VC, BC, Turbo Pascal, etc.) have great differences when dealing with some statements, which causes some of the same statements to have different results in different compilation environments. The following example is given:

1. The space allocated for the variable is different: for INT I, Double J. These two statements are compiled in the VC6.0 environment, the system is I, J assignment space is 4, 8 bytes, respectively. However, when compiling in a TC environment, the space is 2, 4 bytes, respectively. If you are not familiar with the different characteristics of these compilation systems, sometimes there will be some errors. For example, when switching data between programs written in different compilation platforms, the case where the error data is incorporated between the uniform allocation space. There is a solution that solves this mismatch in VC6.0.

2, have you ever thought about why INT A [] [20] can correctly define a two-dimensional array correctly, but Int a [20] [] is not the correct definition? This is related to the compilation system different when processing arrays. In the C / C language, the number of arrays is prioritized, in the first definition method above, if you want to access a [10] [0], you can be based on the array A The address of an element is obtained by adding A [10] [0], address (a [10] [0]) = address (a [0] [0]) 10 * 20 2. But for the second definition, you cannot obtain the address of the A [10] [0] through the address of the first element of A. Because there is such a problem, the C / C language has made a corresponding definition specification. However, the addressing method for some arrays is a priority language, and the second way is correctness, and the first definition method is wrong.

3, everyone knows that in C , the initialization of the metallin is based on the order from left to right, which is mainly related to the parameter stack of C functions. This feature of C has led to a function of using the default parameters, you must pay attention to a rule: in the right side of the default value, the parametric cannot be present. The following example shows: For example, Void Try (int J, INT K = 2, INT M), since the initialization of the parameter is the order of left to right, so if the function is called with TRY (1, 2) At the time, the programmer is intended to call TRY (1, 2, 2), but when compiling in the VC6.0 environment, the compiler believes that the programmer is a value of 1, k assignment is 2, not assiable for m, So VC6.0 thinks wrong. In order to avoid this unnecessary error, it will set a rule. In some languages, the initialization of the arithmetic is in the order from right to left, the rules are over.

4, finally give an example, please see the following questions.

INT W, Z, X, Y;

W = 5; x = 4;

Y = W * w * w ;

z = - x * - x * - x;

What is the value of the last w, z, x, y?

This issue has different results in different compilers. In the VC6.0 environment, for Y = W * W * w , the computer is doing this: first take the w value to multiprain, then W 3 times self-add, that is, y = 5 * 5 * 5 = 125; w = 8. For z = - x * - x * - x, the computer is doing this: first x self-decrement twice, take X multiplication, X is then reduced once, and then multiplied with the results of the previous multiplication. Therefore, z = 2 * 2 * 1 = 4; x = 1. However, in the VC.NET environment and the BC3.1 environment, the result is not this: for Y = W * W * w , the computer is doing this: first take the w value to multiprain, then W 3 times self-add, Y = 5 * 5 * 5 = 125; w = 8; pair z = - x * - x * - x, computer is doing this: first X is reduced three times, take X multiplication. Therefore, z = 1 * 1 * 1 = 1; x = 1. Why do you have this difference? Because the language standards are not defined in the language standard, the various compilers have done their own deals (although some processing is unable to understand). Because there are many cases of the compiler that cause the same statement to have different processing, this article is not intended to be listed one by one. The purpose of this article is to cause everyone to do more thinking and comparisons for the processing of different compilers, which have great help to in-depth learning computer languages.

转载请注明原文地址:https://www.9cbs.com/read-11700.html

New Post(0)