Mono code generation of alien code generation

zhaozj2021-02-11  226

Mono code generation of alien code generation

The reduction code does not mean adding readability, just contrary, excessive reduction code will make the code more difficult to understand, difficult to maintain. This article does not advocate abuse of twisting alien C grammar, just as a hunt record, readers who begin to begin a language C-send language briefly introduce how the inexplicable code is made.

The C sent language provides us with a lot of strange operators, one of the most strange operators, a comma operator, which does not have much actual meaning "calculation", just calculate the value of each operation, and then The value of the rightmost operation item is returned. But this makes us might combine multiple expressions into one:

a = 1;

B ;

C * = 4;

Combined as:

A = I, B , C * = i;

Oh, it seems that it is not a lot, but if it is used in the loop, it is different:

While (i

{

a = i;

B ;

i ;

}

It is abbreviated as:

While (a = i , b , i

In C , since the output statement that uses the COUT isometric is actually an expression, the code for printing the entire array of values ​​for the following common:

For (i = 0; i

COUT << a [i] << endl;

Using a comma operator and utilizing the characteristics of self-intement, it can be short-handed as:

For (i = 0; i

For the operation of printing a two-dimensional array, the outer loop (traversing each line) has to be used after the loop is completed.

For (i = 0; i

{

For (j = 0; j

COUT << a [i] [j];

Cout << Endl;

}

But if you move Cout to the loop, you can significantly reduce the number of lines:

For (i = 0; i

For (j = 0; j

Of course, it can also be

For (i = 0; cout << Endl, i

For (j = 0; cout << a [i] [j], j

But when using a comma operator, you must pay attention to its implicit uncertainty, such as expressions:

i, cout << a [i], x y;

If the language of the respective expression is uncertain in the language, then the A [i] output from the sub-expression of COUT cannot be determined to be self-added I or the I. use comma operators, and related The continuous expression of the overload operator should pay special attention to this.

Note: Due to time rush, this document is unbursed, if there is a mistake, welcome criticism.

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

New Post(0)