I've used this macro before to determine the element count of an array
#define ELEMENTS(x) (sizeof(x)/sizeof(x))
but with 1.8.12, it says:
invalid application of 'sizeof' to incomplete type 'long int '
It's a very useful macro and I'd like to get it working again. Did something change or am I doing it wrong?
is the size of the array known in the file where ELEMENTS is used? is the array defined in a different file
I have a header file that declares the array using the extern keyword (empty rank). Then in the main ino file, it is defined with its element size. The macro is defined in the header file but used in another cpp file.
The size of an array has to be known at compile time, not link time, so size of arrays in external modules
is unknown to the compiler.
If the array has global scope as defined in the INO file and the header file uses extern in its declaration and each file reads the header file, I thought the INO compiles before the cpp files, so those external functions know about and can use the data in their modules.
thought the INO compiles before the cpp files, so those external functions know about and can use the data in their modules.
then a successful compile would depend on the order that files are compiled
if you define int x in one file, an attempt to do sizeof(x) in another file with extern int x will fail. Even though you specified x. When I tried doing a sizeof() with gcc on my laptop, it errored with "incomplete type int
Yep, I think you’re right. If I rename the offending file from *.cpp to *.ino, the macro expansion works just fine. I guess I’ll drop the macro, as I lose incremental compiles when I have multiple ino files…not worth it.