April 26, 2012
Nick Sabalausky:

> Yea, I've got no problem with both (other than sometimes the fully-unaliased
> one can be really, really long.) But at the very least, the type *as used*
> needs to be shown. The unaliased form isn't bad to have too, but it's
> typically of lesser importance..

See:
http://d.puremagic.com/issues/show_bug.cgi?id=5004

Bye,
bearophile
April 27, 2012
> We can't just use Typedef!(void*) or Typedef!(int) because -=/+= will
> be allowed, which shouldn't be allowed for handles. const(void*) won't
> work either, because you should be allowed to assign one handle to
> another and const forbids that.

struct None; // undefined struct as bottom type
alias None* HWND;
enum INVALID_HANDLE_VALUE = cast(HWND)-1;

static assert(__traits(compiles, {HWND h; h = INVALID_HANDLE_VALUE;}));
static assert(!__traits(compiles, {None n;}));
static assert(!__traits(compiles, {HWND h; ++h;}));
static assert(!__traits(compiles, {HWND h; h + 1;}));

HWND foo(HWND h)
{
    return h;
}

void main()
{
    HWND h;
    assert(h is null);
    h = foo(h);
    assert(h is null);
    h = foo(INVALID_HANDLE_VALUE);
    assert(h is INVALID_HANDLE_VALUE);
    h = foo(null);
    assert(h is null);
}
April 28, 2012
On 25/04/2012 21:28, Andrej Mitrovic wrote:
<snip>
> This works well I think:
> struct HWND { }

If it does, it shouldn't, because that struct is of the wrong size.

Windows handles are, AIUI, always of the platform pointer size.  A zero-size handle type would be useless, as only one distinct handle could exist that way.

Stewart.
April 28, 2012
Stewart Gordon:

> Windows handles are, AIUI, always of the platform pointer size.
>  A zero-size handle type would be useless, as only one distinct handle could exist that way.

struct HWND {}
void main() {
    static assert(HWND().sizeof == 1);
}


Bye,
bearophile
April 28, 2012
On 4/28/12, Stewart Gordon <smjg_1998@yahoo.com> wrote:
> If it does, it shouldn't, because that struct is of the wrong size.

Yeah sorry, I didn't properly test this but just tried compiling it. It should be the size of the pointer, yup.
1 2
Next ›   Last »