Hacker News new | ask | show | jobs
by pqomdv 4106 days ago
Which definition is that?

You probably though of:

  array  == &array[0]
which is always true.

This:

  (void*)&array   == (void*)&array[0]
which simplifies to:

    (void*)&array   == (void*)array
is not.

C doesn't guarantee that the values of &array and array are the same. The types T( * )[ * ] and T* are not even compatible and those two pointers are allowed to have different sizes and representation.

1 comments

The first element of an array is located at the address of an array. Even if the pointer-to-array and pointer-to-element types have different size and representation, they point to the same place. The resulting pointer-to-void converted values must point to that place, and have the same type.

This relationship is also true between a pointer to a struct and a pointer to the first element. And also among pointers to the elements of a union.