Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
December 11, 2006 dmd 178 changes | ||||
---|---|---|---|---|
| ||||
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 |
December 11, 2006 Re: dmd 178 changes (177 not 178) and more | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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 |
December 11, 2006 Re: dmd 178 changes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant Attachments: | 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
|
December 11, 2006 Re: dmd 178 changes (177 not 178) and more | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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
|
December 11, 2006 Re: dmd 178 changes (177 not 178) and more | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ant | 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.
|
December 11, 2006 Re: dmd 178 changes (177 not 178) and more | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | You're right, and it all makes sense. Thank you, TK, Unknown and L. Ant |
Copyright © 1999-2021 by the D Language Foundation