www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Char[] suffix 'c' operates differently than cast(char[])

reply David L. Davis <SpottedTiger yahoo.com> writes:
// charsuffix.d
// WinXP SP2 / dmd v0.132
private import std.stdio;

void test(in char[] s)
{
writefln("bool test(in char[] s)");
}

void test(...)
{
writefln("bool test(...)");
}

int main()
{
test("string");             // Calls void test(in char[] s)
test(128U);                 // Calls void test(...)
test(cast(char[])"string"); // Calls void test(in char[] s)

/*
* charsuffix.d(29): function charsuffix.test called with argument types:
*   (char[6])
* matches both:
*   charsuffix.test(char[])
* and:
*   charsuffix.test(...)
*/
//test("string"c);
return 0;
}

It appears that a casted string literal is handed differently then a string
literal using the new string suffixes, shouldn't these work exact same way?

David L.

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
-------------------------------------------------------------------

MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Sep 22 2005
parent =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David L. Davis schrieb:

 // charsuffix.d
 // WinXP SP2 / dmd v0.132
 private import std.stdio;
 
 void test(in char[] s)
 {
 writefln("bool test(in char[] s)");
 }
 
 void test(...)
 {
 writefln("bool test(...)");
 }
 
 int main()
 {
 test("string");             // Calls void test(in char[] s)
 test(128U);                 // Calls void test(...)
 test(cast(char[])"string"); // Calls void test(in char[] s)
 
 /*
 * charsuffix.d(29): function charsuffix.test called with argument types:
 *   (char[6])
 * matches both:
 *   charsuffix.test(char[])
 * and:
 *   charsuffix.test(...)
 */
 //test("string"c);
 return 0;
 }
 
 It appears that a casted string literal is handed differently then a string
 literal using the new string suffixes, shouldn't these work exact same way?
 
 David L.
Added to DStress as http://dstress.kuehne.cn/run/v/variadic_argument_07_A.d http://dstress.kuehne.cn/run/v/variadic_argument_07_B.d http://dstress.kuehne.cn/run/v/variadic_argument_07_C.d http://dstress.kuehne.cn/run/v/variadic_argument_07_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFDNkVf3w+/yD4P9tIRArAlAKDEPS5FEX+E3k4CFKrHmCLYE+Hy7ACgg+Oo /gEkoPYFeMcTO+Tck9MtKV0= =LtHS -----END PGP SIGNATURE-----
Sep 24 2005