Difference between uint8_t* vs uint8_t

徘徊边缘 提交于 2019-12-24 17:23:01

问题


What is the difference/use for these 2 types? I have a basic understanding regarding pointers but I just can't wrap my head around this.

uint8_t* address_at_eeprom_location = (uint8_t*)10;

This line found in an Arduino example makes me feel so dumb. :)

So basically this is a double pointer?


回答1:


The uint_t is the unsigned integer, this is the data stored directly in the memory. The uint_t * is the pointer to the memory in which the number is stored. The (uint_t*) is cast of the 10 - (literal which is translated to a number in the memory so the binary representation of the number ten) to the pointer type. This will create the storage to store the 10, and than will use its address and store it in the address_at_eeprom_location variable.




回答2:


uint8_t is an unsigned 8 bit integer

uint8_t* is a pointer to an 8 bit integer in ram

(uint8_t*)10 is a pointer to an uint8_t at the address 10 in the ram

So basically this line saves the address of the location for an uint_8 in address_at_eeprom_location by setting it to 10. Most likely later in the code this address is used to write/read an actual uint8_t value to/from there.

Instead of a single value this can also be used as an starting point for an array later in the code:

uint8_t x = address_at_eeprom_location[3]

This would read the 3rd uint8_t starting from address 10 (so at address 13) in ram into the variable x



来源:https://stackoverflow.com/questions/25161873/difference-between-uint8-t-vs-uint8-t

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!