For a while, I've been representing large powers of 10 in constants using scientific notation, just so I don't have to count the zeros. e.g.
#define DELAY_USEC 1e6 A colleague pointed out that this isn't safe, because it's not an integer and is not guaranteed to always equal 1000000 exactly. Documentation seems to confirm this, but I'm wondering if its true in practicality. Is there any way to safely declare a power-of-ten integer using a shorthand? Is it safe just to cast it to an int in the define?
static const int SEC_TO_MILLI = 1000; static const int SEC_TO_MICRO = 1000 * SEC_TO_MILLI;this often helps me avoid needing complicated error-prone number literals.