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

推荐订阅源

MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
V
Visual Studio Blog
G
Google Developers Blog
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
C
Check Point Blog
D
Docker
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
博客园 - 叶小钗
博客园 - 聂微东
The Cloudflare Blog
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
腾讯CDC
S
SegmentFault 最新的问题
博客园 - 【当耐特】

Last Blog

CMU 15-213 Attack Lab GAMES101 [1] Affine Transformation & Projection CMU 15-213 Bomblab CMU 15-213 [1] Scribe.cx 2 - 对话与持久化存储 关于 X11 与 Wayland 的剪贴板同步问题 关于 X11 与 Wayland 的剪贴板同步问题 Scribe.cx 1 - 跨浏览器的插件侧板控制 Page Assist 2025 年终总结 2025 年终总结 Linuxqq 粘贴板同步问题 关于所谓“配置工程师” 记一次小端序内存的实际体现 CS110L L3 - Memory Safety in Rust CS110L L2 - Program Analysis CS110L L1 - Safety in System Programming 在 Neovim(v0.10+) 上使用 arduino-language-server PA3 - Batch Processing System 2024 年终总结 Arcaea 曲名匹配器 Arcaea 曲名匹配器 PA W9 - Linking & Loading Hyprland 二周目 Hyprland 二周目 PA2 Part 2 - Emulated Hardware Device PA W8 - IO Devices PA2 Part 1 - Instruction Set Implementation & KLIB Learning Makefile with PA 阅读 MQTTX 项目:Protobuf Test Case
Learn C the Hard Way
Last · 2024-10-30 · via Last Blog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef __DBG_H__
#define __DBG_H__

#include "log.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>

#ifdef NDEBUG
#define debug(M, ...)
#else
#define debug(M, ...) \
fprintf(stderr, ANSI_FMT("DEBUG %s:%d: " M "\n", ANSI_BG_BLACK), __FILE__, \
__LINE__, ##__VA_ARGS__)
#endif

#define clean_errno() (errno == 0 ? "None" : strerror(errno))

#define log_err(M, ...) \
fprintf(stderr, \
ANSI_FMT("[ERROR] (%s:%d: errno: %s) " M "\n", ANSI_FG_RED), \
__FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)

#define log_warn(M, ...) \
fprintf(stderr, \
ANSI_FMT("[WARN] (%s:%d: errno: %s) " M "\n", ANSI_FG_YELLOW), \
__FILE__, __LINE__, clean_errno(), ##__VA_ARGS__)

#define log_info(M, ...) \
fprintf(stderr, ANSI_FMT("[INFO] (%s:%d:) " M "\n", ANSI_FG_BLUE), \
__FILE__, __LINE__, ##__VA_ARGS__)

#define check(A, M, ...) \
if (!(A)) { \
log_err(M, ##__VA_ARGS__); \
errno = 0; \
goto error; \
}

#define sentinel(M, ...) \
{ \
log_err(M, ##__VA_ARGS__); \
errno = 0; \
goto error; \
}

#define check_mem(A) check((A), "Out of memory.")

#define check_debug(A, M, ...) \
if (!(A)) { \
debug(M, ##__VA_ARGS__); \
errno = 0; \
goto error; \
}

#endif