[英]values store in struct
i'm new to C language. 我是C语言的新手。 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 * *有关
struct mmc_davinci_host
请参考此网站http://lxr.free-electrons.com/source/drivers/mmc/host/davinci_mmc.c#L167 *
The function mmc_priv()
returns a void pointer. 函数
mmc_priv()
返回空指针。 So, where does host
store the returned address since host
is a struct type? 那么,哪里
host
,因为存储返回地址host
是一个结构类型?
Thank you. 谢谢。
Returning void*
does not mean to return a void
pointer. 返回
void*
并不意味着返回void
指针。 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
. 但是,在调用
mmc_priv
之后,应该struct mmc_davinci_host *
为struct mmc_davinci_host *
。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.