I have a solution. I created a type to calculate the smallest unsigned integer for a given constant integer value, applied to your macro, it seems to work well. Also the gcc specific typeof is not needed now, but 't' has to be a constant.
template <bool _Flag, typename _True, typename _False> struct If{ typedef _True Result; };
template <typename _True, typename _False> struct If<false, _True, _False>{ typedef _False Result; };
template< uint64_t _Number >
class BestFitUInt{
protected:
enum{
T64 = _Number >> 0x20,
T32 = _Number >> 0x10,
T16 = _Number >> 0x08,
};
typedef typename If< T16, uint16_t, uint8_t >::Result TypeB;
typedef typename If< T32, uint32_t, TypeB >::Result TypeA;
private:
public:
typedef typename If< T64, uint64_t, TypeA >::Result Result;
};
#define BFUI(n) BestFitUInt< n >::Result
#define runEvery(t) for (static BFUI(t) _lasttime;\
(BFUI(t))((BFUI(t))millis() - _lasttime) >= (t);\
_lasttime += (t))
void setup(){
Serial.begin(9600);
};
void loop() {
runEvery(500) Serial.println("500 milliseconds have passed since last printed");
runEvery(100) {
Serial.print("Sensor Value: ");
Serial.println(analogRead(A1));
}
}