3 ms·
A lot of people know to do this, but I have met a shocking amount of C++ developers that know nothing of <stdint.h>. And here we have a prime example of Chrome
by dottrap 11y ago
A lot of people know to do this, but I have met a shocking amount of C++ developers that know nothing of <stdint.h>.
And here we have a prime example of Chrome, a major cross-platform project with high visibility that is not using these types nor didn't define their own in this case. These types were intended to help reduce mistakes. But compiler fragmentation basically resulted in organizations avoiding it, leading to these types of mistakes that could have been avoided in the first place.
- cpeterso 11y agoGoogle's C++ style guide recommends using int unless a fixed size is needed, such as binary compatibility in network code or file formats.
- albinofrenchy 11y agohttps://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Integer_Types https://google-styleguide.googlecode.com/svn/trunk/cppguide.... Maybe I'm reading this wrong, but to me it seems like this is saying go ahead and use the fixed size variants whenever, but it is still OK to use int when you need <=32 bits.
- chetanahuja 11y agoYeah it's al lukewarm endorsement of int, quite possibly there only to accommodate legacy code. "<stdint.h> defines types like int16_t, uint32_t, int64_t, etc. You should always use those in preference to short, unsigned long long and the like, when you need a guarantee on the size of an integer. Of the C integer types, only int should be used."
- albinofrenchy 11y agoI work with a MSVC guy who not only didn't know about stdint, but also thought/thinks that 'word' means 16 bits, and insists that the WORD typedef is more portable than uint16_t. Still, at least nowadays there is no excuse -- everything from TI to VC++ supports stdint variations.