www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - int** should be compatible to void**?

reply "Katayama Hirofumi MZ" <katayama.hirofumi.mz gmail.com> writes:
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.
Jan 22 2014
next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/22/2014 12:36 AM, Katayama Hirofumi MZ wrote:
 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?

While void is untyped data, void* is definitely typed data.
Jan 22 2014
prev sibling next sibling parent reply Kenji Hara <k.hara.pg gmail.com> writes:
--e89a8f5022d60f8b0504f08b6818
Content-Type: text/plain; charset=UTF-8

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 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.

--e89a8f5022d60f8b0504f08b6818 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>Because it is definitely unsafe.</div><div><br></div>= <div>void main()</div><div>{</div><div>=C2=A0 =C2=A0 int n;</div><div>=C2= =A0 =C2=A0 int* pn =3D &amp;n;</div><div>=C2=A0 =C2=A0 int** ppn =3D &amp;p= n;</div><div><br></div><div>=C2=A0 =C2=A0 void** ppv =3D ppn; =C2=A0 // if = this is allowed...?</div> <div><br></div><div>=C2=A0 =C2=A0 double x;</div><div>=C2=A0 =C2=A0 double*= px =3D &amp;x;</div><div><br></div><div>=C2=A0 =C2=A0 // double* is implic= itly convertible to void*</div><div>=C2=A0 =C2=A0 *ppv =3D px;</div><div><b= r></div><div>=C2=A0 =C2=A0 // Wow, now int** points the double* data!</div> <div>=C2=A0 =C2=A0 assert(*ppn is cast(void*)px);</div><div>}</div><div><br=
</div><div>Kenji Hara</div></div><div class=3D"gmail_extra"><br><br><div c=

a href=3D"mailto:katayama.hirofumi.mz gmail.com" target=3D"_blank">katayama= .hirofumi.mz gmail.com</a>&gt;</span><br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex">Hello, this is a Japanese programmer, katahi= romz.<br> <br> If TYPE1 was compatible to TYPE2, I think TYPE1* should be compatible to TY= PE2*.<br> <br> Why isn&#39;t int** type compatible to void** type?<br> <br> What&#39;s your idea? Thanks.<br> </blockquote></div><br></div> --e89a8f5022d60f8b0504f08b6818--
Jan 22 2014
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 01/22/2014 01:25 AM, Katayama Hirofumi MZ wrote:

 Oh, I see. Thanks, Kenji san.

Going off topic, that answers a question of mine! :) I could not be sure whether Kenji san, Hara san, or even Hara-san would be correct when I wrote to a Japanese person. Ali P.S. Going even more off topic, that person did not respond to my email yet. ;)
Jan 23 2014
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 01/23/2014 11:09 AM, Stanislav Blinov wrote:
 On Thursday, 23 January 2014 at 19:00:45 UTC, Ali Çehreli wrote:

 P.S. Going even more off topic, that person did not respond to my
 email yet. ;)

Maybe you actually did get it wrong? :)

I hope not. :) Ali
Jan 23 2014
prev sibling next sibling parent "Katayama Hirofumi MZ" <katayama.hirofumi.mz gmail.com> writes:
Oh, I see. Thanks, Kenji san.

On Wednesday, 22 January 2014 at 09:04:31 UTC, Kenji Hara wrote:
 Because it is definitely unsafe.

Jan 22 2014
prev sibling next sibling parent "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
On Thursday, 23 January 2014 at 19:00:45 UTC, Ali Çehreli wrote:

 P.S. Going even more off topic, that person did not respond to 
 my email yet. ;)

Maybe you actually did get it wrong? :)
Jan 23 2014
prev sibling parent "Jakob Ovrum" <jakobovrum gmail.com> writes:
On Thursday, 23 January 2014 at 19:00:45 UTC, Ali Çehreli wrote:
 On 01/22/2014 01:25 AM, Katayama Hirofumi MZ wrote:

 Oh, I see. Thanks, Kenji san.

Going off topic, that answers a question of mine! :) I could not be sure whether Kenji san, Hara san, or even Hara-san would be correct when I wrote to a Japanese person. Ali

All three are equally correct. Whether to use first or last name is similar to the equivalent split in the anglosphere. Using a hyphen is overwhelmingly common but not required in any system of romanization.
Jan 23 2014