-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std::ssize_t audit #2972
Comments
Eigen uses |
|
In the meeting yesterday, we discussed a few possible typedefs for
|
Sorry I missed. We've generally stuck to lowercase for typedefs internally. I'm also wondering if typedefs that are intended for more broad use tend to be |
My personal preference is also for all lowercase. Leaning towards |
Another point I would like to add is that adding multiple typedefs for indices, offset (for file offsets) and strides with the same underlying idea is not a bad idea. There are very few downsides and it would make it easier if at some point we want to change the types. |
Yes, I think that was suggested the last time we discussed it, and I agree there's no real reason to stick with a single typedef. But on the other hand, there may be a few edge cases where it's not clear which one is most appropriate (though it admittedly wouldn't make any difference...). Furthermore, we are very unlikely to ever define these differently, given how often we'll be mixing them up. For example, computing the offset to the current voxel data in an image involves multiplying the strides by the indices and summing them to produce an offset - all 3 types in one expression... So my preference would be to stick with a single typedef, and try to find one that is sufficiently broad to encompass all 3 uses. Thought I'll freely admit I'm not sure |
Another name that came to my mind was to use |
I'm quite happy to have multiple typedefs that resolve to the same underlying type. I've used that in some places. Often it helps to communicate the intent / appropriate usage of the data at hand. What it doesn't catch is instances of implicit conversion between them, as there's no corresponding compiler warning for eg. loss of precision. Though perhaps once they are typedef'd we could (optionally temporarily) replace those typedefs with classes with explicit casts? If something is an "index", I'd expect that to be a Other factor here is that STL uses
I'd be concerned about the subtlety of the distinction between |
Problem identified by @daljit46.
In various parts of the C++ code base, we have erroneously used
std::ssize_t
as "a signed integer of the same bit width asstd::size_t
, when in fact by the letter of the specification it is only guaranteed to support the value -1.std::ssize_t
where negative values smaller than -1 need to be supported.std::size_t
that involve casting between signed and unsigned integer types to silence compiler warnings, and reconsider types used.(Eg. Pretty sure on at least one occasion I removed a non-functional assertion that a
size_t
be non-negative; may be other areas where catching negative values as errors may be better than using usigned)The text was updated successfully, but these errors were encountered: