Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Then use long.. Does Arduino CPU cannot do 16bit add/sub with carry? wtf?




I'm not writing the app. The app was written according to your preferred design and I'm compiling it for Arduino. You say to just use int because it always has enough bits, then you say to sometimes use long because int might not have enough bits.

I dont know the indented use. If you need delay or difference, 16bit is more than enough. If you writting generic clock w/ ms accuracy, it will be not enough. You either split it or use larger storage. Its not rocket science...

There is a platform where int has less than the prescribed 16 bits? How much does it have then, just 8bit or something weird?

Arduino has 16-bit int, so the timer app will work up to 32.767 or 65.535 seconds, that is less than two minutes.

When you choose unsigned int for that type, you compare against UINT_MAX and return an EOVERFLOW, ENOMEM, EOUT_OF_RANGE or whatever you like when someone sets a timer greater than that. Or you choose another type, i.e. unsigned long which is guaranteed to take values to at least 4294967295. I happen to program for the Arduino platform recently and milliseconds in the Arduino API are typed unsigned long.

If your decision is that you really want to store all 32-bit values then you use uint_least32_t or uint_fast32_t depending if you are also resource constrained.


Right, so you can't just use int.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: