logitech mouse logitech mouse - 1 month ago 5
C Question

c program can `uint8_t` point to an address of size 32 bit

In the code below

get_pic()
returns a pointer of
uint8_t type
.

Then in
main()
,
get_pic()
is called and its return value is cast to the variable
address
which is an
unsigned int
.

The pointer that
get_pic()
returns is to a global array which turns out to be at address
a8000f80
.

My question is that address
a8000f80
is a 32 bit number. Therefore, how can the pointer returned by
get_pic()
point at this address as it is of type
uint8_t
which is only 8 bits?

//Function declaration
uint8_t* get_pic(int *piclen);

main() {

unsigned int address, value;
address = (unsigned int) get_pic((int*)& value);
}

Answer

An uint8_t cannot point anywhere, because it's not a pointer. But an uint_8* (pointer to uint8_t) can.

You probably want this:

uint8_t* get_pic(int *piclen);

main() {
  uint8_t *address;
  int value;

  address = get_pic(&value);
}

get_pic returns a uint8_t *, that is a pointer to uint8_t), therefore the type of address should uint8_t *.

The parameter passed to getpic is of type pointer to int (int*), therefore value should be of type int* too.

Comments