Feature request: ssize_t, a signed size_t
Julio César Carrascal Urquijo
jcarrascal at gmail.com
Fri Mar 4 12:54:56 PST 2011
I was writing something like the following code:
// double y1, y2, width;
size_t index = to!size_t((x2 - x1) / width);
if (index >= 0 && index < grid.length) {
...
} else {
...
}
When I finished writing the condition I remembered that size_t is
actually an uint so it can't be negative.
Just for fun I tested this:
writeln(to!size_t(-1));
std.conv.ConvOverflowException at std\conv.d(8): Error: overflow Conversion
negative overflow
That's not what I was expecting but it's OK. For my use case I changed
the code use int but, with 64bit already here, that's not quite correct.
So if I may suggest: Could we have a signed size_t in Phobos? ssize_t or
with another name.
I don't want to replace size_t. I just want a signed type that's correct
for storing an index for an array in 32 and 64 bit.
PS: I realize this has been discussed before. I just hope we get some
luck this time. <g>
Thanks
More information about the Digitalmars-d
mailing list