The number of groups in C / C is a very strange thing, what does it represent? For char Array [N] (N is a constant), there are probably such semantics: <1> char * const (notice is const char *) <2> char [n]
For example, the following (Win2000 Pro platform, compilation under VC.NET 7.1): <1> char * p = array; // array indicates that Char * const, p get the first address of the array
Size_t size = sizeof (char [n]); // size is equal to N
<2> char (* p) [n] = & array; // array Indicates Char [n], // p The first address char (* Q) [N] = array; // Compiling errors
Char (* r) [n] = (char (*) [n]) Array; // r Getting is the first address of the array array
<3> char (& P) [n] = array; // array represents char [n]
<4> Void foo (Char a [n]) {int size = sizeof (a); // size == 4 (32-bit system), // because A actually represents char *};
Foo (array); // Array Represents Char * Const <5> Void Foo (& A) [N]); {INT SIZE = SizeOf (a); // size == n};
Foo (array); // array represents char [n]
<6> void foo (char (* a) [n]); {int size = sizeof (* a); // size == n};
Foo (& array); // array indicates char [n]
<7> char * p; array = p; // Compile error "error C2440, unable to convert from char * to char [n]", // So Array represents char [N]
<8> char = 中;; // Compile error "Error C2106, '=' left operating number must be l value", // So Array represents char [n]
(CHAR (&) [N]) Array = Other; // Perform the 32-bit number of four elements indicated by the ARRAY is the same as the array address of the other representative of Other, // This is explained here in char * const
(CHAR (&) [N]) Array = (CHAR [N]) Other; // Performed the 32-bit number indicated by the first four elements of Array after execution, the same number of headers indicated by Other
(CHAR (&) [N]) Array = (CHAR (&) [N]) Other; // After execution, the array array is equal to the head four elements of the Other array.
(CHAR (* &) [N]) Array = (CHAR (*) [n]) Other; // (CHAR (* &) [N]) indicates a reference type, // This reference is associated with a point pointing CHAR [N] Array pointer, // Perform the 32-bit number of the first four elements of Array, the same number of 32 digits represented by the other (__int64 &) array = (__int64 &) other; // After execution, Array array Other array of heads 8 elements
<9> long i = 0; (long &) array = i; // actually changed the value of the array itself, // is the first 4 elements (32 bits) in the array representative, // therefore array Representing char [n]
<10> long i = 0; (CHAR (&) [N]) i = array; // assumes that the array number of the first addresses are 0x0012FEAc, // The instruction is executed after I == 0x0012FEAC
<11> long i = 0; (CHAR (&) [N]) i = (CHAR (&) [N]) Array; // Perform the value of the after I is equal to the 32 digits represented by the Array head 4 elements (32 Bit system) <12> (char * &) array = "string"; // executing the 32-bit number of four elements represented after execution The 32-bit number representing the // "String" constant string is the same in memory
<13> (CHAR (&) [N]) Array = (CHAR (&) [N]) "String"; // array array head 4 elements are 's',' t ',' r ',' I '
When we carry out the forced conversion such as Char [N]), the effect is comparable to the "Char * const) array conversion, which is interpreted as a pointer to represent the first address. But both still have a subtle difference: sizeof (char [n]) is equal to N, SIZEOF (CHAR * ConST) equal to 4 (32-bit system), and the conversion such as array (CHAR [M]) is not allowed, where M does not equal n. If we enforce the number of group names with some reference type, the compiler will automatically associate the conversion result (reference type) to the memory area starting from the array of first addresses, regardless of the memory area where the array name itself (does it really exist It is an unknown in memory). When we use this forced converted array name to assign the left operation number of the value, change is the array memory area represented by the array name, and the size of the memory area is changed to the reference type, such as __int64 & So size is 8 bytes, and the rest is pushed. Because (CHAR [N]) is basically equivalent to the (Char * const) effect, the result is interpreted as a pointer, so (char (&) [n]) and (char * const &) are basically quite, the result is explained Associate a reference to the pointer. When using (CHAR (&) [N]) Array, the right operand is actually read from the memory area of the Array pop-up address, and then assigns the left operation . This can be explained why (char (&) [N]) array = (CHAR (&) [N]) Other execution Array's head 4 elements of Other.
Supplement on December 19, 2004: I have summed the semantics, I am not accurate enough, now extract the ANSI C standard as follows: (1) When an array identifier appears in the expression, the type of this identifier is from "An array of type T" is converted to "pointer to type T", and its value is equal to the address of the first element of the array. However, when the array identifier is used as an operand for the SIZEOF and the address (&) operation, the sizeOf returns the size of the entire array, and the address operation returns to the pointer to the array (rather than pointing to a value). Pointer of the pointer of the element address). (2) The following expressions cannot produce LVALUE: array names, functions, enumerations, and assignment expressions, mandatory type conversions, function calls. According to the above statement, it can basically infer the semantics of the number of names of the C program, but this does not cover C , I don't have ISO C standards in hand, so I am very uncertain. However, it is certain that C is complicated because there is a reference type. For example, the value of the value of Lvalue is not generated in C, and C has different explanations.
INT A; (a = 10) = 1000;
These two lines of code are illegal in C, but is completely legal in C .
In addition, some people say that the GCC pairs (5) will also compile errors, and the author uses MINGW3.1.0 (G 3.2.3) test to find it. Because the temporary variables are not generated in (5), only the partial reference type variable A in the initialization function is used, which is a completely legal action.
Supplement on July 1, 2005: Compile with MINGW3.1.0 (G 3.2.3), as long as the forced conversion of char (&) [N]) Array is not included, the error message is: Cannot Convert` Char * 'TO `CHAR [N]' in Converting. Similarly, (char * &) array is also wrong because Array is a type char * RVALUE, which is not allowed to convert to a Non-Const reference type, and it is viable (char * const & array, but according to CHAR) * const & array = "string" does not have any effect on the Array array (whose estimation is due to the temporary variable of a char * const & type, initialize this variable, so there is no impact on Array).