3 ms·
For cross platform interoperability, API with the exact size type helps remove any ambiguity. Using size_t might be fine for intra-process usage, but as soon a
by ww520 11y ago
For cross platform interoperability, API with the exact size type helps remove any ambiguity. Using size_t might be fine for intra-process usage, but as soon as we are dealing with data across platforms, exact size type definition is a must.
- raverbashing 11y ago> Using size_t might be fine for intra-process usage, but as soon as we are dealing with data across platforms, exact size type definition is a must. I don't know why you are downvoted, but this is very important. Never send anything "on the wire" (or to a file) unless you know its exact size and endianness.
- sharpneli 11y agoThat is correct. For file formats and packets etc you must use exact sizes. However for cross platform support using size_t in an API (as in what is exposed via .dll or .so) is a must. It's exactly the correct way to write cross platform code.
- deleted 11y ago[deleted]
- arximboldi 11y agoI see it the other way around. How many bits you need to address something in memory depends on the platform. Thus `size_t` is the only cross-platform type you can use. A fixed-size integral is going to work on some, but not all.