Skip to content
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

Open
TheLoneWolfling opened this issue Jun 26, 2016 · 5 comments
Open

What type should array / string lengths be? #28

TheLoneWolfling opened this issue Jun 26, 2016 · 5 comments

Comments

@TheLoneWolfling
Copy link
Collaborator

Just flat-out 64 bits? A defined type?

Currently about half the lengths are ints and about half are longs.

@incrediblesound
Copy link
Member

I feel like 64 bits is overkill, do you think we could use size_t?

@TheLoneWolfling
Copy link
Collaborator Author

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.

@TheLoneWolfling
Copy link
Collaborator Author

Any more thoughts on this?

@incrediblesound
Copy link
Member

tbh this is a bit outside the scope of my knowledge, so I will appreciate anything you add in this domain.

@TheLoneWolfling
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants