Overload issue between char[] and char*, inwhich the postfix should solve
David L. Davis
SpottedTiger at yahoo.com
Tue Nov 28 13:39:47 PST 2006
Hi Walter,
Please note the comments were placed in the source code below, to
point out the believed to be bug.
// OverLord.d
private import std.stdio;
alias std.stdio io;
int main()
{
char[] sd = "char[] dynamic var works!";
char * sp = "char * dynamic var works!\0";
printValue(sd); // Works fine.
printValue(sp); // Works fine.
//uses the cast(char[])
printValue(cast(char[])"cast(char[]) literal works!");
//uses the cast(char *)
printValue(cast(char *)"cast(char *) literal works!\0");
// ** Bug **
// Now a problem without a cast(), but when using the
// 'c' postfix, it should make it clear that it's a char[]
// parameter. There shouldn't be a matching error here.
// ------------------------------------------------------------
// The error parameter matchs both char[] and char*
// overlord.d(19): function overlord.printValue called
// with argument types: (char[56])
// matches both:
// overlord.printValue(char[])
// and:
// overlord.printValue(char*)
printValue("char[] literal with postfix \'c\' should work, but
doesn\'t"c);
// ** Not a Bug **
// Problem without a cast(), but that's ok...
// since a literal is not typed at this point,
// thus it doesn't know if it is a char[], wchar[], or dchar[]
//printValue("char[] literal, would never work");
return 0;
}
void printValue( in char[] s )
{
io.writefln("printValue(in char[]) called, value=%s", s);
}
void printValue( in char* s )
{
io.printf("printValue(in char *) called, value=%.*s\n", &s);
}
Thanks,
David L.
More information about the Digitalmars-d-bugs
mailing list