随笔-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 @ 2023-08-12 11:04  LiYanbin  阅读(5)  评论(0编辑  收藏  举报