随笔-C-指针数组使用简记

64位
typedef struct mem_list* cns_detail_encode_result[encode_type_max];

(gdb) p &((  struct mem_list**)0x7fffb4557950)[0] # & 取对应点的位置
$29 = (  struct mem_list **) 0x7fffb4557950
(gdb) p ((  struct mem_list**)0x7fffb4557950) + 0 
$30 = (  struct mem_list **) 0x7fffb4557950
(gdb)  
(gdb)  
(gdb) p &((  struct mem_list**)0x7fffb4557950)[1]
$31 = (  struct mem_list **) 0x7fffb4557958
(gdb) p ((  struct mem_list**)0x7fffb4557950) + 1
$32 = (  struct mem_list **) 0x7fffb4557958
(gdb)  
(gdb)  
(gdb) p ((  struct mem_list**)0x7fffb4557950)[1] # 没有& 取对应地址的值
$33 = (  struct mem_list *) 0x0
void test(struct epoll_event *events, int count)
{
    struct epoll_event *item;
    int i;
    
    for (i = 0; i < count; i++) {
        item = &events[i];
        ...
    }
}

int main(int argc, void *argv[])
{
    struct epoll_event events[4] = { 0 };
    ...
    test(events, 4);
    ...
}
posted @   LiYanbin  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示