www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dmd 178 changes

reply Ant <duitoolkit yahoo.ca> writes:
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
next sibling parent reply Ant <duitoolkit yahoo.ca> writes:
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
next sibling parent "Unknown W. Brackets" <unknown simplemachines.org> writes:
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
prev sibling parent reply Lionello Lunesu <lio lunesu.remove.com> writes:
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
parent %u <duitoolkit yahoo.ca> writes:
You're right, and it all makes sense.

Thank you, TK, Unknown and L.

Ant
Dec 11 2006
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----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