how do I make an alias for a const version of an alias in D 2.0?

Steven Schveighoffer schveiguy at yahoo.com
Wed Nov 7 06:50:09 PST 2007


"Jarrett Billingsley" wrote
> I wouldn't necessarily trust the output of .stringof; it's known to be 
> buggy in a lot of cases.  See if you can get the compiler to spit out an 
> error containing the type, i.e.
>
> void blah(T)()
> {
>    SOME_INVALID_FUNCTION();
> }
>
> ...
>
> blah!(PCHAR)();
>
> This should make the compiler spit out some kind of error with the name of 
> the instantiated blah, type included.

An actual problem of this very nature is what triggered my post, my example 
was a dumbed down version :)  I assure you, the compiler is making the 
mistake, not stringof.

Here is a clearer example:

alias char * PCHAR;
alias const(PCHAR) C_PCHAR;
alias const(char *) C_PCHAR2;

void f1(C_PCHAR arg)
{
}

void f2(C_PCHAR2 arg)
{
}

void main()
{
  f1("hello");
  f2("hello");
}

compiler:
testme.d(15): function testme.f1 (char*) does not match parameter types 
(invariant(char[5u]))
testme.d(15): Error: cannot implicitly convert expression ("hello") of type 
invariant char[5u] to char*

Note if I comment out the call to f1, the file compiles.

-Steve 




More information about the Digitalmars-d-learn mailing list