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 parent reply Kenji Hara <k.hara.pg gmail.com> writes:
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.
Jan 22 2014
parent reply "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
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
next sibling parent reply "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
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 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