Wednesday, May 25, 2022

[SOLVED] How to decode struct pointer with function?

Issue

I know how struct pointers work in general. But for struct spi_controller * spi_busnum_to_master(u16 bus_num),

  1. What is holding the address of the struct spi_controller it is pointing towards ?
  2. Can someone decode the logic of this declaration?. ( this style creating struct pointers)

From my understanding, a struct pointer is to enable a variable hold the address of some structure that it points to.


Solution

struct spi_controller * spi_busnum_to_master(u16 bus_num) declares spi_busnum_to_master to be a function taking a parameter of type u16 and returning a pointer to struct spi_controller.

The return value is passed by whatever method is defined by the Application Binary Interface for the target platform. Often it is in a processor register.



Answered By - Eric Postpischil
Answer Checked By - Senaida (WPSolving Volunteer)