Anand said:
Flash said:
It's not quite right. &array is always different from array, they
differ in type. So, given your definition above, the compiler *must*
complain if you pass &array to a function with a prototype in scope
specifying a pointer to char. [...]
Eaaach.. bad mistake from my side!!!
It so happened that in my compiler, the _values_ of array and &array
were same. So without using much of my gray matter I replied stating
array and &array are same.
(Again when I was talking about function.. I meant the _values_ specific
to my compiler's implementation.)
The point a lot of people seem to miss (not just in
this thread, but in many others like it, which is why there's
a FAQ on the topic) is that in C there is no such thing as a
typeless value. A value in C always has a type, and cannot
be divorced from its type.
There is no direct way to compare values of different
types (or perhaps I should say "really different" types,
since qualifiers like `const' don't matter). The `=='
operator requires that both operands be of the same type.
If they start out as different types, one or both must
undergo conversion until new derived values of a common
type are found. These derived values are not the same as
the originals, because their types are different from those
of the originals.
For some reason people seem more prone to overlook this
matter when thinking about pointers than when thinking about
other types. Nobody thinks 42 and 42L and 42LL and 42.0f
and 42.0 and 42.0L are the same, yet confusion over `array'
and `&array' persists. I speculate that this may be because
people think of pointers as addresses when in fact they are
more: they are "typed addresses," addresses plus information.
The address tells you where to find something in memory, while
the type information tells you how to understand what you find
there.
True, in most implementations the extra information is
implicit and does not show up in something like a core dump --
but that's not unusual. There's lots of implicit information
floating around in a compiled program that a core dump won't
reveal. If a core dump or debugger tells you that some variable
holds `FEDCBA98', can you tell what value is represented? No.
Can you tell whether the value is positive or negative? No,
you can't even tell whether the concept of "sign" makes any
sense for this variable. Without knowledge of the type, you
have no idea how to make sense of this batch of bare hex digits.
In C, type and value are inseparable.