菜鸟问题

zll_lover 2011-03-16 01:33:09
//多线程时对该函数的调用是有加锁的
static void item_link_q(item *it) { /* item is the new head */
item **head, **tail; /* always true, warns: assert(it->slabs_clsid <= LARGEST_ID); */
assert((it->it_flags & ITEM_SLABBED) == 0);

head = &heads[it->slabs_clsid];
tail = &tails[it->slabs_clsid];
assert(it != *head);
assert((*head && *tail) || (*head == 0 && *tail == 0));
it->prev = 0;
it->next = *head;
if (it->next) it->next->prev = it;
*head = it;
if (*tail == 0) *tail = it;
sizes[it->slabs_clsid]++;
return;
}
请问此处声明为二级指针,但是我觉得声明一级指针为什么不可以呢?谢谢
...全文
69 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zll_lover 2011-03-16
  • 打赏
  • 举报
回复
哦貌似明白了谢谢各位
zll_lover 2011-03-16
  • 打赏
  • 举报
回复
//多线程时对该函数的调用是有加锁的
static void item_link_q(item *it) { /* item is the new head */
item *head, *tail; /* always true, warns: assert(it->slabs_clsid <= LARGEST_ID); */
assert((it->it_flags & ITEM_SLABBED) == 0);

head = heads[it->slabs_clsid];
tail = tails[it->slabs_clsid];
assert(it != head);
assert((head && tail) || (head == 0 && tail == 0));
it->prev = 0;
it->next = head;
if (it->next) it->next->prev = it;
head = it;
if (*tail == 0) tail = it;
sizes[it->slabs_clsid]++;
return;
}

即使这样请问有什么不对的吗?
delphiwcdj 2011-03-16
  • 打赏
  • 举报
回复
否则就用引用,二级指针类似下面的例子

void GetMemory2(char **p, int num)
{
*p = (char *)malloc(num);
}
void Test(void)
{
char *str = NULL;
GetMemory(&str,100);
strcpy(str,hello);
free(str);
printf(str);
}


bdmh 2011-03-16
  • 打赏
  • 举报
回复
你可以不用二级指针,那样你需要修改其他的代码,你还可以用三级指针,随你,不过如楼上所说,如果你要涉及到修改指针本身,就需要用到二级指针了
quwei197874 2011-03-16
  • 打赏
  • 举报
回复
对head,tail作修改就得用二级指针,否则不用.

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧