Hızlı yanıt: kod örneği
An unsigned long on an Arduino has 32 bits, so the simulator is doing what I would expect an actual Arduino to do.On desktop PCs, an unsigned long can either have 32 or 64 bits, depending on the operating system, the hardware, and the compiler.The printf in your gcc test showed a 64-bit value, so on your platform, it appears those unsigned longs have 64 bits. Since that's different than what you'd get on an Arduino, getting a different result is not surprising. Both results look correct and consistent for their respective platforms, so I'm not sure where the confusion lies.Virtually all C and C++ platforms let you get exactly 32-bit unsigned integers when that's what you want:
- In C, you include and use the type
<stdint.h>
.uint32_t
- In C++, you include and use the type
<cstdint>
.std::uint32_t