Skip to content

zhongguo1987/structc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STRUCT C 基础库

开发背景 : 基于注册, 构建可用的 C 基础库
适用人群 : 有点喜欢 C, 尝试搭建项目的人群

好像才刚开始 ~

核心点:
    q.h         队  列
    mq.h        原子 q
    dict.h      字  典
    tstr.h      字符串
    list.h      单链表
    rtree.h     红黑树
    array.h     动态数组

总设计:
    json, cas, pipe, errno, socket ...

来协助我们搭建 C 项目, 提供底层数据结构和额外组件的支持 ...

...

代码风格, 希望最贴近原生 api :

#include <pthread.h>
#include <semaphore.h>

//
// node_f - 销毁当前对象节点
//  : void list_die(void * node);
//
typedef void (* node_f)(void * node);

//
// start_f - pthread create func
//  : int * run(int * arg)
//
typedef void * (* start_f)(void * arg);

//
// pthread_async - 启动无需等待的线程
// frun     : node_f or start_f 运行的主体
// arg      : 运行参数
// return   : 0 is success, -1 is error
// 
inline static int pthread_async(void * frun, void * arg) {
    pthread_t id;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    int ret = pthread_create(&id, &attr, frun, arg);
    pthread_attr_destroy(&attr);
    return ret;
}

也许要扯些

structc 环境搭建

- Winds 双击
    - 只维护 x64 的 Debug 和 Release
    - Best New CL Build

- Linux 搞起
    - Release : make
    - Clean   : make clean
    - Debug   : make D=-D_DEBUG

- 工程目录述
    - main 目录
        - main_run.c  业务代码起点
        - main_init.c 写单例, 各初始化
        - main_test.c 加 test 目录下单测
    - test 目录
        - *_test.c -> void *_test(void) { ... }

IDE 弱议

Winds 还是万年不变的 Visual Studio Best Version

Linux 抛砖引玉带大家配置哈 VS Code Best Version

0. 安装 C/C++ Microsoft 插件

1. F1 -> Edit Configurations -> c_cpp_properties.json
   Search Linux 部分添加如下内容
            "name": "Linux",
            "includePath": [
                ...
                "${workspaceRoot}/structc/base",
                "${workspaceRoot}/structc/struct",
                "${workspaceRoot}/structc/system"
            ],
            "defines": [
                "_DEBUG",
                "__GNUC__"
            ],
2. F5 -> launch.json
   按照规律改 program 项目生成 和添加 preLaunchTask 前置任务行
            "program": "${workspaceFolder}/Out/main.exe",

            "preLaunchTask": "Debug",
3. F1 -> [>Tasks: Configure Build] -> [Enter] -> [Others] -> tasks.json
   建立下面任务
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type"    : "shell",
            "label"   : "Debug",
            "command" : "make D=-D_DEBUG"
        },
        {
            "type"    : "shell",
            "label"   : "Release",
            "command" : "make"
        },
    ]
}
核心思路是基于 Makefile Debug 模式配置 VSCode C Studio.
此刻就可以在 main.c 入口出发, 开启 F5 F10 F11 玩耍之路.

比 gcc + gdb + vi 好那么一丢丢 ~

~ * ~ 写个好手

为要寻一个明星
- 徐志摩

我骑着一匹拐腿的瞎马,
向着黑夜里加鞭;——
向着黑夜里加鞭,
我跨着一匹拐腿的瞎马!

我冲入这黑绵绵的昏夜,
为要寻一颗明星;——
为要寻一颗明星,
我冲入这黑茫茫的荒野。

累坏了,累坏了我胯下的牲口,
那明星还不出现;——
那明星还不出现,
累坏了,累坏了马鞍上的身手。

这回天上透出了水晶似的光明,
荒野里倒着一只牲口,
黑夜里躺着一具尸首。——
这回天上透出了水晶似的光明!

...................o888888o.o88888888o.
.................8888888888888888888888888o.
...............888::::888888888888888888888888o.
.............88::::::::88888888888888888888888888o.
...........o8:::::::::888::顶88888888888888888888888.
..........8888:8::::::8:::::::::顶88888888888888888888.
.........8888::::8888::::::::::::::::顶88888888888 '88
........8888:::888888888::::::::::::::::顶888888888 8
.......88.88888888888888888:::::::::::::顶88888888888
......88..888888888888888888:::::::::::顶88888888888888
......88.888888888888888888888::::::::顶88888888888888888
......8..8888888888888888888888::::::顶88888888888888888888
........8888888888888888::88888:::::顶8888888888888888888888
......88888888888888888::::8888::::顶8888888888888888 '8888
.....88888888888888888::::8888::::顶:8::***::888888888 888
....88888888888888888::::888:::::顶::::*EYE*::888888888 88
..888888888888888888::::88::::::顶:::::::::::::888888888 88
.8888888888888888888::::8::::::顶:::::::::::::顶888888888 88
888...8888888888::88::::8:::::顶:::8oo8::::::88888888888888 8
88...88888888888:::8:::::::::顶:::::::::::::88888888888888888
.8..8888888888888:::::::::::顶::"8888888":::顶88888888888888888
..8888888888::888::::::::::顶:::::"8a8"::::顶88888888888888888888
.888888888:::::88:::::::::顶88::::::::::::顶88888888888888888888888
8888888888:::::8:::::::::顶88888::::::::顶888888888888888888888888888
888888888:::::8:::::::::顶8888888ooooo顶8888888888888888888888888888888
888888.::::::::::::::顶8888888888::::::顶8888888888888888 '888888888
8888..:::::::::::::::顶88888888888::::::顶8888888888888888 88888888
.888..::::::::::::::顶8888888888888:::::::顶888888888888888 888888
..888.:::::::::::::顶88888888888888888::::::顶8888888888888 88888
...88.:::::::::::::8888:88888888888888888:::::顶顶888888888 8888
...88.:::::::::::8888::88888::888888888888:::::顶顶88888 888
...8...::::::::::8888:::8888:::::88888888888::::::顶顶88 888
.......8:::::::8888:::::888:::::::88:::8888888:::::::顶顶 88
......88:::::::8888::::::88:::::::::8:::::888888::::::::顶顶 88
.....8888:::::888:::::::::88::::::::::::::8888:::::::::::: 8
....88888:::::888::::::::::8:::::::::::::::888::::::::::::::
...88.888::::888:::::::::::8::::::::::::::888::::::::::::::::
...8.88888:::88:::::::::::::::::::::::::::88::::::::::::::::::
.....88888:::88:::::::::::::::::::::::::::顶88:::::::::::::::::::
.....88888:::88::::::::::::::::::::::::::::8::::::::::::::::::::
....888888::::8::::::::::::::::8888::::::::顶8::::::::::::8888:::::
....88888..:::8::顶顶:::::::::::888888:::::::::::::::::::888888::::
....8888...顶顶:::::顶顶::::::::::888888:::::::顶顶::::::::::888888::::
....8888....:::::::顶顶::::::::::8888:::::::顶顶顶::::::::::8888::::'
.....888....顶顶::::::顶顶顶:::::::::::::::::顶顶::::::::::::::::::'
......88.....::::::::顶顶顶顶:::::::::::顶顶顶:::顶顶:::::::::::::'
.......88....顶顶:::::::::顶顶顶顶顶顶顶顶顶顶:::::::顶顶顶顶顶顶顶顶'
........88....顶顶::::::::::::顶顶顶顶顶顶顶::::::::::::顶顶顶顶顶o'
.........88...8顶顶::::::::::::::::::::::::::::::::::::::::
..........8...88顶顶:::::::::::::::::::::::::::::::::::
..............888顶顶::::::::::::::::::顶顶::::::顶顶::::::
.............88888顶顶:::::::::::::::顶顶顶:::::::顶顶:::::
.............888888顶顶:::::::::::::顶顶顶:::::::::顶顶:::
............88888888顶顶:::::::::::顶顶顶::::::::::::::
...........88.8888888.::::::::顶顶顶::::::::::::::::
...........8..888888..::::::顶顶:::::::::::::::::::
..............888888..::::::::::::::::::::::::::顶顶
.............888888...::::::::::::::::::::::::::::顶顶
.............888888...:::::::::::::::::::::::::::::
.............88888...::::::::::::::8::::::::::::::::::
............88888...:::::::::::::::88::::::::::::::::::
...........88888...::::::::::::::::8::::::::::::::::::::
..........88888...::::::::::::::::::::::::::::::::::::
..........8888...::::::::::::::::::::::::::::顶顶::::::::
.........8888...::::::::::::::::::::::::::::顶顶顶::::::::
........888....:::::顶顶::::::::::::::::::::::顶顶顶:::::::::
......8888....::::::顶顶:::::::::::::::::::::顶顶顶::::::::: :
.....888......::::::::::::::::::::::::::::顶顶:::::::::::::::
..8888.......:::::::::::::::::::::::::::::::::::::::::::::::::
.............:::::::::::::::::::::::::::::::::::::::::::::::::::
............::::::::::::::::::::::::::::::::::::::::::::::::::
............::::::::::::::::::::::::::::::::::::::::::::::::
...........:::::::::::::::::::::::::::::::::::::::::::::::::
...........:::::::::::顶8::::::::8:::::::::::::::::::::::::::顶p
...........::::::::::::888hole888顶::::::::::::::::::::::::::::顶o
...........:::::::::::::88888888::::::::::::::::::::::::::::顶p
...........::::::::::::::888888:::::::::::::::::::::::::::::
...........:::::::::::::::88888::::::::::::::::::::::::::::
...........:::::::::::::::::88::::::::::::::::::::::::::::顶顶
...........::::::::::::::::::::::::::::::::::::::::::::::顶顶
...........:::::::::::::::::::::::::::::::::::::::::::::顶顶
............:::::::::::::::::::::::::::::::::::::::::::顶顶
............:::::::::::::::::::::::::::::::::::::::::::
.............:::::::::::::::::::::::::::::::::::::::::
.............::::::::::::::::::::::::::::::::::::::::
..............::::::::::::::::::::::::::::::::::::::
..............::::::::::::::::::::::::::::::::::::
...............::::::::::::::::::::::::::::::::::
...............:::::::::::::::::::::::::::::::::
................:::::::::::::::::::::::::::::::
................::::::::::::::::::::::::::::::
.................::::::::::::::::::::::::::::
..................::::::::::::::::::::::::::
..................:::::::::::::::::::::::::
...................:::::::::::::::::::::::
...................::::::::::::::::::::::
....................::::::::::::::::::::
....................顶顶:::::::::::::::::::
....................顶顶::::::::::::::::::
....................顶顶:::::::::::::::::
....................顶顶:::::::::::::顶顶
....................顶顶::::顶顶:::::::顶顶
....................顶顶::::::顶顶:::::顶顶
.....................顶顶::::::::::::::顶顶
.....................顶顶:::::::::::::顶顶
......................顶顶::顶顶顶:::::::顶顶
......................顶顶::顶顶顶:::::::顶顶
......................顶顶:::顶顶::::::::::
.......................顶顶::顶顶::::::::::
.......................顶顶::顶顶:::::::::::
.......................顶顶:::::::::::::::
.......................顶顶:::::::::::::::::
.......................顶顶:::::::::::::::::
.......................顶顶::::::::::::::::::
.......................顶顶::::::::::::::::::
.......................顶顶::::::::::::::::::
........................顶顶:::::::::::::::::
........................顶顶:::::::::::::::::
........................顶顶:::::::::::::::::
........................顶顶:::::::::::::::::
........................顶顶:::::::::::::::::
.........................顶顶:::::::::::::::
.........................顶顶:::::::::::::::
.........................顶顶:::::::::::::::
.........................顶顶::::::::::::::
..........................顶顶:::::::::::::
..........................顶顶:::::::::::::
..........................顶顶:::::::::::::
..........................顶顶::::::::::::
..........................顶顶::::::::::::
...........................顶顶:::::::::::
...........................顶顶::::::::::
...........................顶顶::::::::::
............................顶顶::::::::
............................顶顶::::::::
............................顶顶::::::::
.............................顶顶:::::::
.............................顶顶:::::::
..............................顶顶::::::
..............................顶顶::::::
..............................顶顶::::::
..............................顶顶::::::
..............................顶顶::::::
..............................顶顶::::::
.............................顶顶:::::::
............................:::::::::
............................::::::::::
............................:::::::::::
............................::::::::::::
............................:::::::::::::
............................::::::::::::::
............................:::::::::::::::
............................顶顶:::::::::::::::::
..............................顶顶::::::::::::::::
................................顶顶顶:::::::::顶顶
..................................顶顶::::::顶顶
...................................顶顶顶顶顶顶顶
......................................顶顶顶顶顶

:)

-:> Wuayramanta


About

Lightweight C structure base libraryhttps://www.cnblogs.com/life2refuel/p/7706253.html

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 99.6%
  • Other 0.4%