Yeah I basically took the idea from the existing D implementation.
Although D's arrays are a struct with a length and a pointer (I think
so).
On 04/16/2011 06:55 AM, Andrej Mitrovic wrote:
I wonder.. in all these years.. have they ever thought about using a
convention in C where the length is embedded as a 32/64bit value at
the pointed location of a pointer, followed by the array contents?
Sometimes called "Pascal strings" (actually,
Microsoft has some of the most ridiculous functions. This one
(GetEnvironmentStrings) returns a pointer to a block of
null-terminated strings, with no information on the count of strings
returned. Each string ends with a null-terminator, standard stuff. But
only when you find two null terminators i
Hmm.. now I need a function that converts a wchar* to a wchar[] or
wstring. There doesn't seem to be anything in Phobos for this type of
conversion. Or maybe I haven't looked hard enough?
I don't know whether this is safe since I'm not sure how the null
terminator is represented in utf16, but it d
On 4/1/11, Jacob Carlborg wrote:
> In those cases, doesn't the function return the length of the filled
> data or something like that?
I know what you mean. I would expect a C function to do just that, but
in this case it does not. Its lame but I have to deal with it.
On 3/31/11 11:18 PM, Andrej Mitrovic wrote:
Actually, this still suffers from the problem when the returned char*
doesn't have a null terminator. It really sucks when C code does that,
and I've just experienced that. There is a solution though:
In those cases, doesn't the function return the le
Oh I'm not trying to get this into Phobos, I just needed the function
so I wrote it and sharing it here. Maybe it should throw. For my
purposes I don't need it to throw. :)
Andrej Mitrovic Wrote:
> Actually, this still suffers from the problem when the returned char*
> doesn't have a null terminator. It really sucks when C code does that,
> and I've just experienced that. There is a solution though:
>
> Since we can detect the length of the D array passed into
> `fr
On 3/31/11, Jesse Phillips wrote:
> Why not:
>
> string getNameOld()
> {
> static char[256] name;
> cDispatch(name.ptr, kGetProductName);
> return to!string(name.ptr);
> }
>
Nice catch! But see my second reply. If a null terminator is missing
and we know we're operating on a D a
Actually, this still suffers from the problem when the returned char*
doesn't have a null terminator. It really sucks when C code does that,
and I've just experienced that. There is a solution though:
Since we can detect the length of the D array passed into
`fromStringz`, we can do the job of to!
Why not:
string getNameOld()
{
static char[256] name;
cDispatch(name.ptr, kGetProductName);
return to!string(name.ptr);
}
There are situations where you have to call a C dispatch function, and pass it
a void* and a selector. The selector lets you choose what the C function does,
for example an enum constant selector `kGetProductName` could ask the C
function to fill a null-terminated string at the location of the v
12 matches
Mail list logo