-
Notifications
You must be signed in to change notification settings - Fork 21
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
What type should array / string lengths be? #28
Comments
I feel like 64 bits is overkill, do you think we could use size_t? |
We could indeed use size_t. The difficulty there is then what size should integers be? If we make integers ptrdiff_t, then we introduce different behavior for different platforms w.r.t. integers. But if we don't make integers size_t, then an array or string's length may be larger than the max integer value. There are platforms where sizeof(ptrdiff_t) < sizeof(long), and there are platforms where sizeof(ptrdiff_t) >= sizeof(long). (Though note that "The types used for size_t and ptrdiff_t should not have an integer conversion rank greater than that of signed long int unless the implementation supports objects large enough to make this necessary.") Though even with this said, making integers ptrdiff_t and indexes size_t would be my first choice. Well, or making integers variable-length. Which I could do, if you wanted. |
Any more thoughts on this? |
tbh this is a bit outside the scope of my knowledge, so I will appreciate anything you add in this domain. |
After mulling it over, here's what I'd suggest: Have huo integers be int64_t. It's overkill, yes, but the next step down is 32 bits, and although you're rather unlikely to allocate 2^63 elements, it's easy to allocate 2^31 elements. And you want them to be of some fixed length (rather than changing with platform) as having them be different widths depending on platform is no fun to deal with at all. Have indexes be size_t internally. And just have a function to cast between the two of them that throws an error if it would be out of range. |
Just flat-out 64 bits? A defined type?
Currently about half the lengths are ints and about half are longs.
The text was updated successfully, but these errors were encountered: