I have a project with 10 *.cpp, one *.h, and one *.ino files in it. The header file contains the macro:
- #define ELEMENTCOUNT(x) (sizeof(x) / sizeof(x[0])) // Macro to get array element count,*
In one situation, I call it passing in the name of this array:
const char *contestExchanges[] = { // Exchange Message for Contest or common info:
" ", // Spaces to create 1-based array and used for erasing messages
"CQ CQ CQ DE W8TEE", // General CQ. Change as needed
"599 OH", // DX CW contest exchange
"1D OH", // Field Day See: http://www.arrl.org/files/file/Field-Day/2016/2016%20Rules.pdf
" A W8TEE 54 OH", // SSCW This message is preceeded by an incrementing QSO number:http://www.arrl.org/sweepstakes
"SKN", // Straight Key Night. Send this before RST report"
"CINCINNATI,OH", // QTH
"NAME JACK JACK",
"RIG HB 5W QRP",
"ANT DIPOLE 25 FT", // NOTE: Last entry has no comma at the end. The compiler automatically allocates emough memory
"Woodland Mounds St Pk"
};
using this syntax to call it from a function in the *.ino file:
static int count = ELEMENTCOUNT(contestExchanges) - 1;
It works fine. However, if I move the function that uses the macro to a *.cpp file, it fails with the error message:
MyButtons.h:32: error: invalid application of 'sizeof' to incomplete type 'const char* []'
#define ELEMENTCOUNT(x) (sizeof(x) / sizeof(x[0])) // Macro to get array element count
- ^*
C:\Users\econjack\AppData\Local\Temp\arduino_build_312005\sketch\DisplayManagement.cpp:95:22: note: in expansion of macro 'ELEMENTCOUNT' - static int count = ELEMENTCOUNT(contestExchanges) - 1;*
with the carat pointing to contestExchanges. If I move it back to the *.ino file (where the array is defined) it works fine. I have the array declared in the header file (e.g., using extern) and declared in the *.ino file.
While it is fixed...sort of...I don't understand why it's a problem when move out of the *.ino file.