Im working on a sparetime project, making some server code to an Arduino Duemilanove, but before I test this code on the controller I am testing it on my own machine (An OS X based macbook). I am using ints some places, and I am worried that this will bring up strange errors when code is compiled and run on the Arduino Duemilanove because the Arduino handles ints as 2 bytes, and my macbook handles ints as 4 bytes. Im not a hardcore C and C++ programmer, so I am in a bit of worry how an experienced programmer would handle this situation.
Should I restrict the code with a typedef that wrap my own definition of and int that is restricted to 2 bytes? Or is there another way around?
Im working on a sparetime project, making some server code to an Arduino Duemilanove,
Share
Your best bet is to use the
stdint.hheader. It defines typedefs that explicitly refer to the signedness and size of your variables. For example, a 16-bit unsigned integer is auint16_t. It’s part of the C99 standard, so it’s available pretty much everywhere. See:http://en.wikipedia.org/wiki/Stdint.h