Thread overview
Did typedefs break code?
Sep 11, 2011
Mehrdad
Sep 11, 2011
Mehrdad
Sep 11, 2011
Jonathan M Davis
Sep 11, 2011
Daniel Murphy
September 11, 2011
I just realized some of my code broke because of the (apparent?) changes to typedef.

I had something like:

   extern(Windows) void Foo(HANDLE h);

   const HANDLE h = CreateFile(...);
   Foo(h);

which now broke because Foo's parameter can no longer be const (since HANDLE is now an alias for void*, and so const HANDLE means const(void*), which can't be cast to void*).

Obviously, I can make the variable non-const to solve the problem, but like, was the change to typedef really necessary? Is there a plan to get around problems like these in the long term?
September 11, 2011
On 9/10/2011 5:11 PM, Mehrdad wrote:
> I just realized some of my code broke because of the (apparent?) changes to typedef.
>
> I had something like:
>
>    extern(Windows) void Foo(HANDLE h);
>
>    const HANDLE h = CreateFile(...);
>    Foo(h);
>
> which now broke because Foo's parameter can no longer be const (since HANDLE is now an alias for void*, and so const HANDLE means const(void*), which can't be cast to void*).
>
> Obviously, I can make the variable non-const to solve the problem, but like, was the change to typedef really necessary? Is there a plan to get around problems like these in the long term?
Oh FYI, apparently code like this also broke:

       HANDLE h;
       @property HANDLE handle() const { return h; }

because you can't return const(void*) as void*...
so frustrating. :(
September 11, 2011
On Saturday, September 10, 2011 17:11:56 Mehrdad wrote:
> I just realized some of my code broke because of the (apparent?) changes
> to typedef.
> 
> I had something like:
> 
>     extern(Windows) void Foo(HANDLE h);
> 
>     const HANDLE h = CreateFile(...);
>     Foo(h);
> 
> which now broke because Foo's parameter can no longer be const (since
> HANDLE is now an alias for void*, and so const HANDLE means
> const(void*), which can't be cast to void*).
> 
> Obviously, I can make the variable non-const to solve the problem, but like, was the change to typedef really necessary? Is there a plan to get around problems like these in the long term?

typedef is being removed from the language entirely. In its place we currently have alias and we will have a struct of some kind in Phobos (probably called Typedef or TypeDef) which will allow for something similar to typedef but with a finer grain of control over which conversions are implicit and which are explicit. I believe that typedef stuff was removed from Phobos in several places recently in preparation for the removal of typedef from the language. If that's causing problems, then they need to be identified and sorted out one way or another. Once we have an implementation of Typedef in Phobos is probably when we'll actually deprecate typedef.

- Jonathan M Davis
September 11, 2011
"Mehrdad" <wfunction@hotmail.com> wrote in message news:j4gucr$289g$1@digitalmars.com...
>I just realized some of my code broke because of the (apparent?) changes to typedef.
>
> I had something like:
>
>    extern(Windows) void Foo(HANDLE h);
>
>    const HANDLE h = CreateFile(...);
>    Foo(h);
>

The fact that const(HANDLE) implicitly converted to HANDLE is a bug in dmd. You can insert casts if you still want the same broken behaviour with alias. Apart from that, typedef has been 'unofficailly' deprecated for some time, and removed from (most of) the online documentation.  Hopefully soon it will be officially deprecated in the language, giving a deprecation error when used.