When I run the following code
#include <stdio.h>
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
const uint8_t Symbols[] = {
0xCA,0x04,// size
0x0B, // width
0x0B, // height
0x00, // first char
0x04, // char count
0x01, 0x02, 0x03, 0x04,// char widths
// font data
0x00, 0x00, 0x20, 0x00, 0xF0, 0x07, 0x08, 0x04, 0x84, 0x07, 0x84, 0x07, 0x84, 0x07, 0x0E, 0x04, 0xF0, 0x07, 0x20, 0x00, 0x00, 0x00, // 0
0x10, 0x01, 0x08, 0x01, 0x04, 0x01, 0x04, 0x01, 0x08, 0x01, 0x10, 0x01, 0x10, 0x01, 0x08, 0x01, 0x04, 0x01, 0x04, 0x01, 0x00, 0x00, // 1
0x18, 0x00, 0xFF, 0x07, 0x18, 0x00, 0x00, 0x00, 0x80, 0x01, 0xFF, 0x07, 0x80, 0x01, 0x00, 0x00, 0x0C, 0x00, 0xFF, 0x07, 0x0C, 0x00, // 2
0x00, 0x02, 0x80, 0x05, 0x60, 0x04, 0x18, 0x04, 0x04, 0x04, 0x72, 0x05, 0x04, 0x04, 0x18, 0x04, 0x60, 0x04, 0x80, 0x05, 0x00, 0x02 // 3
};
typedef struct
{
uint16_t size; //2
uint8_t width; //1
uint8_t height; //1
uint8_t first_char; //1
uint8_t char_count; //1
uint8_t *font_widths;
uint8_t *font_data;
} _graphics_font;
_graphics_font* test;
uint8_t* font_st;
uint8_t temp;
int main(void)
{
test = (_graphics_font*)&Symbols;
font_st = (uint8_t*)&test->font_widths;
temp = font_st[0]+font_st[1]+font_st[2]+font_st[3]; //1+2+3+4 = 10
printf("temp=%d",temp);
return 0;
}
in C, I'm expecting that the pointer font_st will point exactly after the 6-th Byte of the Symbols array. Therefore the result printed should be 10. Instead of that the pointer is allocated to the 9-th byte, missing every time 2 bytes and wrongly to my expectations is printing 7 as a result. Why and how could that be?
Important update is that the using instead the line:
temp = font_st[-2]+font_st[-1]+font_st[0]+font_st[1]; //1+2+3+4 = 10
works.