digitalmars.D.learn - dmd 178 changes
- Ant <duitoolkit yahoo.ca> Dec 10 2006
- Ant <duitoolkit yahoo.ca> Dec 10 2006
- "Unknown W. Brackets" <unknown simplemachines.org> Dec 10 2006
- Lionello Lunesu <lio lunesu.remove.com> Dec 11 2006
- %u <duitoolkit yahoo.ca> Dec 11 2006
- Thomas Kuehne <thomas-dloop kuehne.cn> Dec 10 2006
ok, I jump a few releases and missed a lot of discussions...
this isn't valid anymore:
/**
* get the C version of command line in the format char**
*/
static char** getCommandLine(char[][] args)
{
// Walter version from a post on the D news group
char** argv = new char*[args.length];
int i = 0;
foreach (char[] p; args)
{
argv[i++] = cast(char*)p;
}
return argv;
}
how to we do the
char** argv = new char*[args.length];
?
like:
&((new char*[args.length])[0]);
?
Ant
Dec 10 2006
and more, this is invalid:
printf("Couldn't compile sources for "~name.toString()~"\n");
function object.printf (char*,...) does not match parameter types (char[])
but this is valid:
printf("Couldn't compile sources for ");//~name.toString()~"\n");
???
Ant
Dec 10 2006
Use toStringz() or writefln(). -[Unknown]and more, this is invalid: printf("Couldn't compile sources for "~name.toString()~"\n"); function object.printf (char*,...) does not match parameter types (char[]) but this is valid: printf("Couldn't compile sources for ");//~name.toString()~"\n"); ??? Ant
Dec 10 2006
Ant wrote:and more, this is invalid: printf("Couldn't compile sources for "~name.toString()~"\n"); function object.printf (char*,...) does not match parameter types (char[]) but this is valid: printf("Couldn't compile sources for ");//~name.toString()~"\n"); ??? Ant
Well, I think it actually IS invalid. The string in your first example is not zero terminated! A string literal guaranteed to be zero terminated, but a char[] is not. This is a perfect example why [] -> * conversion was removed. L.
Dec 11 2006
You're right, and it all makes sense. Thank you, TK, Unknown and L. Ant
Dec 11 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ant schrieb am 2006-12-11:ok, I jump a few releases and missed a lot of discussions... this isn't valid anymore: /** * get the C version of command line in the format char** */ static char** getCommandLine(char[][] args) { // Walter version from a post on the D news group char** argv = new char*[args.length]; int i = 0; foreach (char[] p; args) { argv[i++] = cast(char*)p; } return argv;
DMD-0.177: Arrays no longer implicitly convert to pointers unless -d is used. /** * get the C version of command line in the format char** */ static char** getCommandLine(char[][] args) { // Walter version from a post on the D news group char** argv = (new char*[args.length]).ptr; int i = 0; foreach (char[] p; args) { argv[i++] = p.ptr; } return argv; } Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFFfQTbLK5blCcjpWoRAuFpAJ9Y9DYi9fMGx1xKKxzao+HwUeiQjQCfZL6H pZj5wV/AHDVFBwniikYlBuI= =LAOW -----END PGP SIGNATURE-----
Dec 10 2006









"Unknown W. Brackets" <unknown simplemachines.org> 