4 ms·
You "know the range", but not necessarily in terms of concrete numbers. Often, you iterate over variable size data structures, for example. All you know is that
by zAy0LfpBZLC8mAC 11y ago
You "know the range", but not necessarily in terms of concrete numbers. Often, you iterate over variable size data structures, for example. All you know is that it won't be larger than the C implementation it's being compiled with allows--which usually roughly means that it won't be larger than the amount of memory the processor it's running on can address. But how much that actually is? Well, depends on the processor, and there also is no upper limit, as you always can invent a processor that can address more memory than any processor before. That's why you should usually use appropriate abstract types (such as size_t in this case) that the compiler will make sure are large enough to be able to iterate over any data structure you will encounter on that target.
- Nursie 11y agoOh sure, for array index stuff like that. For general iteration against another number, say, I would use a fixed (or fast) size appropriate to my data.