i'm new to C language. I have some questions to ask regarding structs.
For example:
static inline void *mmc_priv(struct mmc_host *host)
{
return (void *)host->private;
}
struct mmc_host
{
unsigned long private[0] ____cacheline_aligned;
};
struct mmc_davinci_host *host = NULL;
struct mmc_host *mmc = NULL;
host = mmc_priv(mmc);
host->mmc = mmc;
*for the struct mmc_davinci_host
please refer to this site http://lxr.free-electrons.com/source/drivers/mmc/host/davinci_mmc.c#L167 *
The function mmc_priv()
returns a void pointer. So, where does host
store the returned address since host
is a struct type?
Thank you.
Returning void*
does not mean to return a void
pointer. It means to return a pointer to any type .
In fact, pointers store addresses, and addresses always have the same size, no matter which type is located behind.
However, you should have a cast to struct mmc_davinci_host *
after calling mmc_priv
. I would write it as follows:
/* call mmc_priv and store its result in host, after having cast it to struct mmc_davinci_host * */
host = (struct mmc_davinci_host *) mmc_priv(mmc);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.