2012/8/3 L. David Baron <[email protected]> > I think there are also many cases where we should use either (size_t > and ptrdiff_t) or (intptr_t and uintptr_t), which are not int and > not explicitly sized. In some of these cases we use > PRUint32/PRInt32 today. I think we should be using these for things > that correspond to the size or number of allocations (e.g., the size > of an array, a reference count), since they should correspond to the > size of pointers or number of objects that can be allocated on the > architecture in question. I think doing this avoids some types of > integer overflow bugs. >
Totally agree on the fact that role-specific types like size_t are preferable when they are what is meant! I tend to use size_t for all array indices. > > I'm not sure what the reason to prefer size_t/ptrdiff_t vs. > intptr_t/uintptr_t are (and I hope there aren't any cases where > they're different). I suppose size_t and ptrdiff_t have been around > longer, but intptr_t and uintptr_t have clearer names. But I also > tend to think we should only use one set of them. > The difference is on architectures where segments are smaller than addressable memory. For example, some exotic architectures have 32bit size_t even though pointers are 64 bit. On these architectures, each array may be only 4G even though the address space is greater than 4G. For this reason, when what you mean is really "an integer of the size of a pointer", it is intptr_t / uintptr_t that you want, not size_t. In practice, I don't think that any architecture that we care about exhibits such differences, but it's always better to get this right. And also, as you say, clearer names. Benoit > > -David > > -- > 𝄞 L. David Baron http://dbaron.org/ 𝄂 > 𝄢 Mozilla http://www.mozilla.org/ 𝄂 > _______________________________________________ > dev-platform mailing list > [email protected] > https://lists.mozilla.org/listinfo/dev-platform > _______________________________________________ dev-platform mailing list [email protected] https://lists.mozilla.org/listinfo/dev-platform

