Issue
I have an bin data table, for sample purposes:
static const unsigned char test_bin[28800] = {0};
#define TEST_DATA_COLUMNS 2
#define TEST_DATA_ROWS (sizeof(test_bin)/sizeof(float)/TEST_DATA_COLUMNS);
static const float (* test_data)[TEST_DATA_COLUMNS] = (const float (*)[TEST_DATA_COLUMNS]) test_bin;
This fails with error: expected expression before ';' token
:
for(size_t i = 0; i < TEST_DATA_ROWS ; i++);
But this works
size_t nrows = TEST_DATA_ROWS;
for(size_t i = 0; i < nrows ; i++);
Why?
Solution
The problem is the trailing semi-colon at the end of the define for TEST_DATA_ROWS
#define TEST_DATA_ROWS (sizeof(test_bin)/sizeof(float)/TEST_DATA_COLUMNS);
^
This means that the preprocessor generates the following for your loop
for(size_t i = 0; i < (sizeof(test_bin)/sizeof(float)/TEST_DATA_COLUMNS); ; i++)
^ ^
Removing the ;
from the end of the define would fix things.
Answered By - simonc Answer Checked By - Cary Denson (WPSolving Admin)