问题
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