struct foo {
long a;
float d;
void *some_ptr;
}
struct foo *start_address(void *some_other_ptr) {
return ((struct test *)((char *) linkfield_ptr //Don't know what to do here);
}
int main() {
struct foo fum;
struct foo *foo_ptr;
foo_ptr = start_address(&fum.some_ptr);
}
foo_ptr需要是结构的起始地址,所以基本上start_address方法必须返回该地址。我一直抨击我的头反对这个问题一个小时左右,因为我不允许使用任何宏或外部库来找到答案。对此的回答以及他们如何从指针大师那里得到答案的解释将不胜感激。获取结构开始的起始地址
不是fum = fum = fum的地址的起始地址吗? –
C11草案标准'6.3.2.3指针,第7节[...]当一个对象的指针转换为指向字符类型的指针时,结果指向该对象的最低寻址字节。 – EOF
必须使用struct中的元素才能为start_address方法派生return语句,因此需要调用start_address(&fum.some_ptr)。 @EOF - 必须是C90:p –