need clarification: will typedef, C struct initialization, etc.
Simen kjaeraas
simen.kjaras at gmail.com
Wed Jun 2 15:02:03 PDT 2010
On Wed, 02 Jun 2010 23:12:38 +0200, Adam Ruppe <destructionator at gmail.com>
wrote:
> On 6/2/10, Simen kjaeraas <simen.kjaras at gmail.com> wrote:
> *snip*
>
> I haven't tried your code, but it looks similar to my own code, which
> had this problem:
>
> alias Typedef!Int Handle;
> alias Typedef!Int OtherHandle;
>
> void foo(Handle h) { }
>
> OtherHandle b;
>
> foo(b); // compiles, but shouldn't. Problem is that Handle and
> OtherHandle are both alias of the same underlying thing, so the
> compiler considers them the same thing! With the old typedef, I'm
> pretty sure it would (correctly IMO) complain here.
My code sidesteps that by including instantiation line and file,
making each instantiation unique (as long as you don't do
multiple typedefs on one line).
It is possible to sidestep this issue with a mixin template:
mixin template typedef( string name, T ) {
mixin(q{
struct } ~ name ~ q{ {
//stuff
}
});
}
But 'mixin Typedef!("myInt", int);' does not sit well with me.
--
Simen
More information about the Digitalmars-d
mailing list