On Thu, 04 Oct 2012 01:05:14 +0100, Steven Schveighoffer
wrote:
On Wed, 03 Oct 2012 08:37:14 -0400, Regan Heath
wrote:
On Tue, 02 Oct 2012 21:44:11 +0100, Steven Schveighoffer
wrote:
In fact, a better solution would be to define a C string type (other
than char *), and just pretend t
On Tuesday, 2 October 2012 at 13:07:46 UTC, deadalnix wrote:
Le 01/10/2012 22:33, Vladimir Panteleev a écrit :
On Monday, 1 October 2012 at 12:12:52 UTC, deadalnix wrote:
Le 01/10/2012 13:29, Vladimir Panteleev a écrit :
On Monday, 1 October 2012 at 10:56:36 UTC, deadalnix wrote:
How does to!
On Wed, 03 Oct 2012 08:37:14 -0400, Regan Heath
wrote:
On Tue, 02 Oct 2012 21:44:11 +0100, Steven Schveighoffer
wrote:
In fact, a better solution would be to define a C string type (other
than char *), and just pretend those system calls return that. Then
support that C string type in
On Tue, 02 Oct 2012 21:44:11 +0100, Steven Schveighoffer
wrote:
In fact, a better solution would be to define a C string type (other
than char *), and just pretend those system calls return that. Then
support that C string type in writef.
-Steve
:D
http://comments.gmane.org/gmane.comp.l
On Wednesday, October 03, 2012 07:35:23 Jakob Ovrum wrote:
> > I suppose we could just use @trusted
> > and call it a day.
>
> No, that would be abusing @trusted. The function would no longer
> be safe, *because it contains possibly unsafe code*. @trusted is
> for safe functions that the compiler
On Wednesday, 3 October 2012 at 05:04:01 UTC, H. S. Teoh wrote:
Yes that's what I mean. If the format string is known at
compile-time
and known to involve only @safe code, then this would work.
Something
like this might work if CTFE is used to parse the format string
piecemeal (i.e., translate
On Tue, Oct 02, 2012 at 07:50:09PM -0700, Jonathan M Davis wrote:
> On Tuesday, October 02, 2012 18:21:30 H. S. Teoh wrote:
> > On Wed, Oct 03, 2012 at 03:07:14AM +0200, Andrej Mitrovic wrote:
> > > On 10/3/12, Jakob Ovrum wrote:
> > > > writefln cannot be @safe if it has to support an unsafe form
On Tuesday, October 02, 2012 18:21:30 H. S. Teoh wrote:
> On Wed, Oct 03, 2012 at 03:07:14AM +0200, Andrej Mitrovic wrote:
> > On 10/3/12, Jakob Ovrum wrote:
> > > writefln cannot be @safe if it has to support an unsafe format
> > > specifier. It's "hidden" because it affects every call to writefl
On Wed, Oct 03, 2012 at 03:07:14AM +0200, Andrej Mitrovic wrote:
> On 10/3/12, Jakob Ovrum wrote:
> > writefln cannot be @safe if it has to support an unsafe format
> > specifier. It's "hidden" because it affects every call to writefln,
> > even if it doesn't use the unsafe format specifier.
[...]
On 10/3/12, Jakob Ovrum wrote:
> writefln cannot be @safe if it has to support an unsafe format
> specifier. It's "hidden" because it affects every call to
> writefln, even if it doesn't use the unsafe format specifier.
Ah damn I completely forgot about @safe. I tend to avoid recent features..
O
On Tuesday, 2 October 2012 at 21:30:35 UTC, Andrej Mitrovic wrote:
On 10/2/12, Walter Bright wrote:
On 9/30/2012 11:31 AM, deadalnix wrote:
If you know that a string is 0 terminated, you can easily
create a slice
from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString
On 10/2/12, Walter Bright wrote:
> On 9/30/2012 11:31 AM, deadalnix wrote:
>> If you know that a string is 0 terminated, you can easily create a slice
>> from it as follow :
>>
>> char* myZeroTerminatedString;
>> char[] myZeroTerminatedString[0 .. strlen(myZeroTerminatedString)];
> Since %zs is in
On Tue, 02 Oct 2012 15:35:47 -0400, David Nadlinger
wrote:
On Tuesday, 2 October 2012 at 19:34:31 UTC, David Nadlinger wrote:
Well, make it to!char(char*) then! ;)
Oh dear, this doesn't get better: Of course, I've meant to write
»to!(char[])(char*)«.
Right. I agree, this should not al
On Tuesday, 2 October 2012 at 19:34:31 UTC, David Nadlinger wrote:
Well, make it to!char(char*) then! ;)
Oh dear, this doesn't get better: Of course, I've meant to write
»to!(char[])(char*)«.
David
On Tuesday, 2 October 2012 at 19:31:33 UTC, Steven Schveighoffer
wrote:
On Tue, 02 Oct 2012 15:17:42 -0400, David Nadlinger
wrote:
On Tuesday, 2 October 2012 at 02:22:33 UTC, Steven
Schveighoffer wrote:
@system char[] zstr(char *s) { return s[0..strlen(s)]; }
[…]
Does it make sense for Pho
On Tue, 02 Oct 2012 15:17:42 -0400, David Nadlinger
wrote:
On Tuesday, 2 October 2012 at 02:22:33 UTC, Steven Schveighoffer wrote:
@system char[] zstr(char *s) { return s[0..strlen(s)]; }
[…]
Does it make sense for Phobos to provide such a shortcut in an obscure
header somewhere? Like s
On Tuesday, 2 October 2012 at 02:22:33 UTC, Steven Schveighoffer
wrote:
@system char[] zstr(char *s) { return s[0..strlen(s)]; }
[…]
Does it make sense for Phobos to provide such a shortcut in an
obscure header somewhere? Like std.cstring? Or should we just
say "roll your own if you need it
On Tue, 02 Oct 2012 04:09:43 -0400, Walter Bright
wrote:
On 10/1/2012 7:22 PM, Steven Schveighoffer wrote:
Does it make sense for Phobos to provide such a shortcut in an obscure
header somewhere? Like std.cstring? Or should we just say "roll your own
if you need it"?
As a matter of princip
Le 02/10/2012 03:13, Walter Bright a écrit :
On 9/30/2012 11:31 AM, deadalnix wrote:
If you know that a string is 0 terminated, you can easily create a slice
from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 .. strlen(myZeroTerminatedString)];
It is clean and av
Le 01/10/2012 22:33, Vladimir Panteleev a écrit :
On Monday, 1 October 2012 at 12:12:52 UTC, deadalnix wrote:
Le 01/10/2012 13:29, Vladimir Panteleev a écrit :
On Monday, 1 October 2012 at 10:56:36 UTC, deadalnix wrote:
How does to!string know that the string is 0 terminated ?
By convention
On 10/2/12 4:09 AM, Walter Bright wrote:
On 10/1/2012 7:22 PM, Steven Schveighoffer wrote:
Does it make sense for Phobos to provide such a shortcut in an obscure
header somewhere? Like std.cstring? Or should we just say "roll your own
if you need it"?
As a matter of principle, I really don't l
Andrej Mitrovic wrote:
On 10/1/12, Piotr Szturmaj wrote:
For example C binding writers may change:
extern(C) char* getstr();
to
extern(C) cstring getstr();
I don't think you can reliably do that because of semantics w.r.t.
passing parameters on the stack vs in registers based on whether a
On 10/1/2012 7:22 PM, Steven Schveighoffer wrote:
However, we can't require an import to use a bizarre
specifier, and you can't link un@safe code to a specifier, so the zstr
concept is far superior in requiring the user to know what he is doing,
and having the compiler enforce that.
Yup.
Doe
On Mon, 01 Oct 2012 21:13:47 -0400, Walter Bright
wrote:
On 9/30/2012 11:31 AM, deadalnix wrote:
If you know that a string is 0 terminated, you can easily create a slice
from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 .. strlen(myZeroTerminatedString)];
It
On 9/30/2012 11:31 AM, deadalnix wrote:
If you know that a string is 0 terminated, you can easily create a slice
from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 .. strlen(myZeroTerminatedString)];
It is clean and avoid to modify the stdlib in an unsafe way.
On Monday, 1 October 2012 at 12:12:52 UTC, deadalnix wrote:
Le 01/10/2012 13:29, Vladimir Panteleev a écrit :
On Monday, 1 October 2012 at 10:56:36 UTC, deadalnix wrote:
How does to!string know that the string is 0 terminated ?
By convention (it doesn't).
It is unsafe as hell oO
Forcing t
On 10/1/12, Andrej Mitrovic wrote:
> but the D
> compiler expected the parameters to be passed
missing "in another way" there.
On 10/1/12, Piotr Szturmaj wrote:
> For example C binding writers may change:
>
> extern(C) char* getstr();
>
> to
>
> extern(C) cstring getstr();
I don't think you can reliably do that because of semantics w.r.t.
passing parameters on the stack vs in registers based on whether a
type is a pointe
Johannes Pfau wrote:
struct CString(T)
if (isSomeChar!T)
{
T* str;
}
@property
auto cstring(S : T*, T)(S str)
if (isSomeChar!T)
{
return CString!T(str);
}
string test = "abc";
immutable(char)* p = test.ptr;
writefln("%s", p.cstring); // prints "abc"
Here the char point
On Mon, 01 Oct 2012 05:54:30 -0400, Jonathan M Davis
wrote:
I'm not completely against the idea of %zs, but I confess that I have to
wonder what someone is doing if they really need to print zero-terminated
strings all that often in D for anything other than quick debugging (in
which
case
Le 01/10/2012 13:29, Vladimir Panteleev a écrit :
On Monday, 1 October 2012 at 10:56:36 UTC, deadalnix wrote:
Le 30/09/2012 21:58, Vladimir Panteleev a écrit :
On Sunday, 30 September 2012 at 18:31:00 UTC, deadalnix wrote:
If you know that a string is 0 terminated, you can easily create a
slic
Am Mon, 01 Oct 2012 13:22:46 +0200
schrieb Piotr Szturmaj :
> Paulo Pinto wrote:
> > On Monday, 1 October 2012 at 09:42:08 UTC, Piotr Szturmaj wrote:
> >> Jakob Ovrum wrote:
> >>> On Monday, 1 October 2012 at 09:17:52 UTC, Piotr Szturmaj wrote:
> Adam D. Ruppe wrote:
> > On Saturday, 29 S
Jonathan M Davis wrote:
On Monday, October 01, 2012 11:18:16 Piotr Szturmaj wrote:
Adam D. Ruppe wrote:
On Saturday, 29 September 2012 at 02:11:12 UTC, Alex Rønne Petersen wrote:
While the idea is reasonable, the problem then becomes that if you
accidentally pass a non-zero terminated char* to
On Monday, 1 October 2012 at 10:56:36 UTC, deadalnix wrote:
Le 30/09/2012 21:58, Vladimir Panteleev a écrit :
On Sunday, 30 September 2012 at 18:31:00 UTC, deadalnix wrote:
If you know that a string is 0 terminated, you can easily
create a
slice from it as follow :
char* myZeroTerminatedStrin
Paulo Pinto wrote:
On Monday, 1 October 2012 at 09:42:08 UTC, Piotr Szturmaj wrote:
Jakob Ovrum wrote:
On Monday, 1 October 2012 at 09:17:52 UTC, Piotr Szturmaj wrote:
Adam D. Ruppe wrote:
On Saturday, 29 September 2012 at 02:11:12 UTC, Alex Rønne Petersen
wrote:
Also this reminds me of the u
Le 30/09/2012 21:58, Vladimir Panteleev a écrit :
On Sunday, 30 September 2012 at 18:31:00 UTC, deadalnix wrote:
If you know that a string is 0 terminated, you can easily create a
slice from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 .. strlen(myZeroTerminatedS
On Monday, 1 October 2012 at 09:42:08 UTC, Piotr Szturmaj wrote:
Jakob Ovrum wrote:
On Monday, 1 October 2012 at 09:17:52 UTC, Piotr Szturmaj
wrote:
Adam D. Ruppe wrote:
On Saturday, 29 September 2012 at 02:11:12 UTC, Alex Rønne
Petersen
wrote:
Also this reminds me of the utter uselessness of
On Monday, October 01, 2012 11:18:16 Piotr Szturmaj wrote:
> Adam D. Ruppe wrote:
> > On Saturday, 29 September 2012 at 02:11:12 UTC, Alex Rønne Petersen wrote:
> >> While the idea is reasonable, the problem then becomes that if you
> >> accidentally pass a non-zero terminated char* to %sz, all hel
Jakob Ovrum wrote:
On Monday, 1 October 2012 at 09:17:52 UTC, Piotr Szturmaj wrote:
Adam D. Ruppe wrote:
On Saturday, 29 September 2012 at 02:11:12 UTC, Alex Rønne Petersen
wrote:
Also this reminds me of the utter uselessness of the current behavior of
"%s" and a pointer - it prints the address
On Monday, 1 October 2012 at 09:17:52 UTC, Piotr Szturmaj wrote:
Adam D. Ruppe wrote:
On Saturday, 29 September 2012 at 02:11:12 UTC, Alex Rønne
Petersen wrote:
Also this reminds me of the utter uselessness of the current
behavior of
"%s" and a pointer - it prints the address.
Why not specia
Adam D. Ruppe wrote:
On Saturday, 29 September 2012 at 02:11:12 UTC, Alex Rønne Petersen wrote:
While the idea is reasonable, the problem then becomes that if you
accidentally pass a non-zero terminated char* to %sz, all hell breaks
loose just like with printf.
That's the same risk with to!str
On Monday, 1 October 2012 at 06:58:41 UTC, Paulo Pinto wrote:
You should anyway wrap those APIs not to pollute D call with
lower level APIs.
I have to agree, esp when it applies to pointers.
We should not forget that one of the objectives of D is to make
coding "safe" by getting rid of the ne
On Sunday, 30 September 2012 at 20:27:16 UTC, Andrej Mitrovic
wrote:
On 9/30/12, deadalnix wrote:
If you know that a string is 0 terminated, you can easily
create a slice
from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 ..
strlen(myZeroTerminatedString)];
On Sunday, 30 September 2012 at 19:58:16 UTC, Vladimir Panteleev
wrote:
On Sunday, 30 September 2012 at 18:31:00 UTC, deadalnix wrote:
If you know that a string is 0 terminated, you can easily
create a slice from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 ..
On 9/30/12, deadalnix wrote:
> If you know that a string is 0 terminated, you can easily create a slice
> from it as follow :
>
> char* myZeroTerminatedString;
> char[] myZeroTerminatedString[0 .. strlen(myZeroTerminatedString)];
>
> It is clean and avoid to modify the stdlib in an unsafe way.
>
On Sunday, 30 September 2012 at 18:58:11 UTC, Paulo Pinto wrote:
+1
We don't need to preserve C's design errors regarding strings
and vectors.
The problem is that, unsurprisingly, most C APIs (not just libc,
but also most C libraries and OS APIs) use zero-terminated
strings. The philosophy
On Saturday, 29 September 2012 at 02:07:38 UTC, Andrej Mitrovic
wrote:
I've noticed I'm having to do a lot of to!string calls when I
want to
call the versatile writef() function. So I was thinking, why not
introduce a special zero-terminated string specifier which
would both
alleviate the need
On Sunday, 30 September 2012 at 18:31:00 UTC, deadalnix wrote:
If you know that a string is 0 terminated, you can easily
create a slice from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 ..
strlen(myZeroTerminatedString)];
It is clean and avoid to modify the s
On Sunday, 30 September 2012 at 18:31:00 UTC, deadalnix wrote:
If you know that a string is 0 terminated, you can easily
create a slice from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 ..
strlen(myZeroTerminatedString)];
It is clean and avoid to modify the s
If you know that a string is 0 terminated, you can easily create a slice
from it as follow :
char* myZeroTerminatedString;
char[] myZeroTerminatedString[0 .. strlen(myZeroTerminatedString)];
It is clean and avoid to modify the stdlib in an unsafe way.
On Saturday, 29 September 2012 at 02:11:12 UTC, Alex Rønne
Petersen wrote:
While the idea is reasonable, the problem then becomes that if
you accidentally pass a non-zero terminated char* to %sz, all
hell breaks loose just like with printf.
That's the same risk with to!string(), yes? We aren't
On 29-09-2012 04:08, Andrej Mitrovic wrote:
I've noticed I'm having to do a lot of to!string calls when I want to
call the versatile writef() function. So I was thinking, why not
introduce a special zero-terminated string specifier which would both
alleviate the need to call to!string and would p
52 matches
Mail list logo