Liste des Groupes | Revenir à cl c |
On 30/03/2024 09:32, Tim Rentsch wrote:
>bart <bc@freeuk.com> writes:>
>I was aware of the double conversion but KT used 'a cast' so I>
wondered if there was a single cast that could be used.
There is not, if it's important that it work reliably across
different compilers and different platforms.
>It is odd however that function and object pointers can be>
considered so different that even an explicit conversion
between them is deemed to be meaningless.
Function pointers and object pointers don't have to be the same
size, or use the same form of representation. The C standard
allows implementations where code and data live in completely
separate memories. In such cases there is no sensible way to
convert between the two kinds of pointers, because the two kinds
of addresses have no relationship to each other.
Suppose a object pointer is 32 bits, and a function pointer is a
32-byte descriptor.
>
An implementation could choose to present a function pointer as a
32-bit object pointer, which points to the full 32-byte descriptor in
data memory.
>
The simplest way of doing that is to have, for each function (or each
one whose address is taken), a fixed corresponding descriptor in data
memory. So here function and object pointers can be exactly the same
size, and can both refer to data memory, as far as the programmer is
concerned.
>
Dereferencing such a function pointer, to call the function, will
involve an extra bit of indirection. It would need something extra
anyway to deal with those 32 bytes.
Les messages affichés proviennent d'usenet.