Quote:Original post by Zahlman
You are in agreement. The array has an address. The array NAME does not.
No, I'm afraid we disagree entirely. Going back to Fruny's post it is clear what he means:
Quote:Original post by Fruny
The problem is that table itself doesn't have an address (try doing &table). It is not a variable: table[0], table[1]... are. However, table has a value, which is indeed the address of table[0].
Table in fact
does have an address and &table
is well defined. Here he doesn't differentiate between the array and the array name, as he shouldn't. The name of the array directly represents the array and is no different from the name of any variable, just like in the statement "float var;" you wouldn't differentiate between the var name and the variable itself. The only difference is that with arrays, the language allows for automatic conversion to a pointer to the first element if it is in the context where one is required, which is no different from a class with an overloaded operator int* or even the usual arithmetic conversions that take place such as when adding together two different arithmetic types.
Quote:Original post by Zahlman
It *is* an address, but there is no chunk of memory (at least not one accessible to the programmer, unless he creates another one by making a pointer to the array beginning) storing the value corresponding to that address. It exists only in the mind of the compiler.
No. An array, or the array name if you prefer to call it that, is not, in
any way, an address. An array is a contiguous block of N elements. The name refers to that block of memory just like any variable name refers to the variable it represents. There is no difference.
Edit: As an example relating it to the rest of the language:
void float_function( float& );void double_function( double );void array_function( int (&)[32] );void ptr_function( int* );int main(){ float float_var; float_function( float_var ); // float_var is passed by reference double_function( float_var ); // float_var is converted to double double double_var; float_var == double_var; // float_var is converted to double int array[32]; array_function( array ); // array is passed by reference ptr_function( array ); // array is converted to a pointer to the first element int* ptr; array == ptr; // array is converted to a pointer to the first element}
The point of the above code is to stress that the float isn't a double simply because you can implicitly yield a double from it, just like the array is not a pointer because you can implicitly yield a pointer to the first element. What's more is the array name isn't an address just like the name of a float isn't a double. Just because an instance of a type "A" can be converted to another type "B" does not in any way mean that an instance of the type "A" is an instance of type "B", nor does it mean that the name of that instance is of type "B".
[Edited by - Polymorphic OOP on April 25, 2006 5:46:35 PM]