惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 喜欢Ⅰ

人类随机数趣闻 - 即使人们会觉得它更随机,但实际上它更不随机 项目代码套路 墨菲定律 - 人类一种误判心理 消息队列, 一种取舍的选择 Redis Stream CORS 跨域请求一种后端适配解决方案 自我的智慧 市场教父 André Kostolany Exception Handling Considered Harmful MySQL CREATE TABLE Template 模板设计简单交流 面试题: 字符串转整型 终结者 atomic 原子自增工程案例 - 喜欢Ⅰ HTTP 尝试获取 Client IP 对炒股看法 吃饱年代 我是个怎样的人 格林童话之祖父和孙子 Linux 守护进程 智慧 ~ 引子 ~ 三则故事 交易人生
C 里面如何使用链表 list
喜欢Ⅰ · 2026-02-25 · via 博客园 - 喜欢Ⅰ

可能 C 里面高频业务都依赖 list 增删改查. 这里简单交流下自己在 c 里面使用 list 

1. 学生时代, 那会学习 C 数据结构, 比较简单

struct person {
    int id;
    char name[64+1];
    struct person * next;
};

类似上面这样, 需要什么依赖 next 指针来回调整, 然后手工 print F5 去 debug 熬. 

2. 刚工作青年时代, 主要花活, 随大流

类似

structc/modular/test/list.h at master · wangzhione/structc

#pragma once

#include "struct.h"

//
// list.h 似魔鬼的步伐, 单链表库
// $LIST 需要嵌入 struct 的第一行
// void * list = nullptr;      // create list
// list_delete(list, fide);    // delete list [可选]
//
struct $list {
    struct $list * next;
};

#define $LIST struct $list $node;

或者类似

ccan/ccan/list/list.h at master · rustyrussell/ccan

/**
 * struct list_node - an entry in a doubly-linked list
 * @next: next entry (self if empty)
 * @prev: previous entry (self if empty)
 *
 * This is used as an entry in a linked list.
 * Example:
 *    struct child {
 *        const char *name;
 *        // Linked list of all us children.
 *        struct list_node list;
 *    };
 */
struct list_node
{
    struct list_node *next, *prev;
};

/**
 * struct list_head - the head of a doubly-linked list
 * @h: the list_head (containing next and prev pointers)
 *
 * This is used as the head of a linked list.
 * Example:
 *    struct parent {
 *        const char *name;
 *        struct list_head children;
 *        unsigned int num_children;
 *    };
 */
struct list_head
{
    struct list_node n;
};

 杂技, 理解的心智负担稍微高一点, 但使用上对方有了单元测试, 比较成熟, list 结构问题较少, 除了业务的内存错位自己 debug 稍微麻烦点.  

3. 35岁中年之后, 又想起刚开始那会

skynet/skynet-src/socket_server.c at master · cloudwu/skynet

类似这样

struct write_buffer {
    struct write_buffer * next;
    const void * buffer;
    char * ptr;
    size_t sz;
    bool userobject;
};

struct write_buffer_udp {
    struct write_buffer buffer;
    uint8_t udp_address[UDP_ADDRESS_SIZE];
};

struct wb_list {
    struct write_buffer * head;
    struct write_buffer * tail;
};

需要 list , 还是直接 next 指针来回调整. 

当下各种 ai 加持, 这种方式可能是最简单最直接, 当然 c 写代码相对麻烦, 多做好单元测试.

人生也类似, 兜兜转转一个圈, 那种圈在时空维度看, 是螺旋上升的. 

不知道有没有人好奇, 为什么不直接一开始就上升呢, 可能生命不需要赶着投胎吧, 浪费不是时间, 也不是人生, 也可能是享受到了时间, 享受到了自己来回波动的人生. 

: ) Good luckly ~

4. 未来时代, 对于个人而言, C 融入自己思维一部分, 可能不再去主动写了. 

类似婴儿那会记忆, 与其说忘了, 可能已经存在于最底层脑海机制里面了.