Address calculation using sizeof() operator
I am a little bit confusing with Address calculation using sizeof() operator.
I am writing a program for DMA transfer half a buffer in a time.
Such as,
---------
1st: HAL_SPI_Transmit_DMA(&hspi1, ptr1, buf_len/2) ;
2nd: HAL_SPI_Transmit_DMA(&hspi1, ptr2, buf_len/2) ;
---------
where ptr1 is pointer to DATA[0] and ptr2 is pointer to DATA[10].
However, when I wrote 2nd one as,
---------
HAL_SPI_Transmit_DMA(&hspi1, ptr1+sizeof(uint16_t)*10, buf_len/2) ;
---------
I got wrong addres for ptr2.
Therefore, I checked the result of sizeof() as below, and found sizeof(uint16_t) does not return same value in address calculation.
---------
uint16_t Data[20] ;
uint16_t * addr0 = Data ; // 0x2000ffbc or 536936380 [base]
uint16_t * addr1 = &(Data[10]) ; // 0x2000ffe4 or 536936420 [base + 20]
uint16_t * addr2 = Data + sizeof(uint16_t)*10 ; // 0x2000ffd0 or 536936400 [base + 40]
int size = sizeof(uint16_t) ; // size = 2
int arraysize = sizeof(Data) / sizeof(Data[0]) ; // arraysize = 20
---------
I suppose uint16_t is 2 byte data as shown in sizeof(uint16_t). Otherwise how can I align 2 byte data in a buffer?
Kindly enlighten me!
Thank you,
