Determine correct size of TICKER_CHARACTER_COUNT

Since tickerCharacters is a char pointer rather than a char array the
result is: sizeof(8) / sizeof(1).
However, desired
result is: sizeof(5) / sizeof(1).

See also following example:

const char *tickerCharacters = "|/-\\";
const char _tickerCharacters[] = "|/-\\";

int main(void)
{
	printf("%zu\n", (sizeof(tickerCharacters) / sizeof(char)));
	printf("%zu\n", (sizeof(_tickerCharacters) / sizeof(char)));

	return 0;
}

> gcc test.c -o test && ./test
8
5
This commit is contained in:
Thomas Stibor 2020-04-13 19:21:22 +02:00
parent fde6c680b3
commit bcc8a05978
1 changed files with 1 additions and 1 deletions

View File

@ -104,7 +104,7 @@ typedef struct pageEntry_s {
uint8_t flags;
} pageEntry_t;
static const char* tickerCharacters = "|/-\\"; // use 2/4/8 characters so that the divide is optimal.
static const char tickerCharacters[] = "|/-\\"; // use 2/4/8 characters so that the divide is optimal.
#define TICKER_CHARACTER_COUNT (sizeof(tickerCharacters) / sizeof(char))
typedef enum {