int** should be compatible to void**?

Kenji Hara k.hara.pg at gmail.com
Wed Jan 22 01:04:03 PST 2014


Because it is definitely unsafe.

void main()
{
    int n;
    int* pn = &n;
    int** ppn = &pn;

    void** ppv = ppn;   // if this is allowed...?

    double x;
    double* px = &x;

    // double* is implicitly convertible to void*
    *ppv = px;

    // Wow, now int** points the double* data!
    assert(*ppn is cast(void*)px);
}

Kenji Hara


2014/1/22 Katayama Hirofumi MZ <katayama.hirofumi.mz at gmail.com>

> Hello, this is a Japanese programmer, katahiromz.
>
> If TYPE1 was compatible to TYPE2, I think TYPE1* should be compatible to
> TYPE2*.
>
> Why isn't int** type compatible to void** type?
>
> What's your idea? Thanks.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140122/ed03d8ee/attachment-0001.html>


More information about the Digitalmars-d mailing list