econjack:
It works fine. However, if I move the function that uses the macro to a *.cpp file, it fails with the error message:
rather than using macros C++ allows the use of constexpr functions:
#include "test.h"
uint8_t pinSet[] {
1,2,3,4,5,6,7,8,9,0,11
};
size_t arraySize = NUM_ELEMENTS(sizeof(pinSet), sizeof(pinSet[0]));
void setup() {
Serial.begin(112500);
Serial.println(arraySize);
}
void loop() {
}
#ifndef TEST_H
#define TEST_H
constexpr size_t NUM_ELEMENTS(size_t i, size_t k) {
return i/k;
}
#endif
the arguments must be compile time constants...
Added benefit is that you won't have #define directive collisions.