摘要:使用C++标准库无法取得std::ifstream对象的文件描述符,但GNU libstdc++库可以取得: #include <fstream> #include <iostream> #include <ext/stdio_filebuf.h> int main() { std::ifstrea
阅读全文
摘要:以下内容全为 chatGPT 生成: ```cpp #include #include #include #include std::string hmac_sha256(const std::string &key, const std::string &data) { unsigned char
阅读全文
摘要:* **特化模板兼容性** 下列代码在 c++17 及之前都是可以的,但从 c++20 开始编译报语法错误: ```cpp // g++ -g -std=c++20 -o x x.cpp;./x #include #include template struct X { X(type t) { th
阅读全文
摘要:执行 configure 生成 Makefile,排除掉不需要的语言支持和测试等: ```bash ./configure --prefix=/usr/local/thrift-0.18.1 --with-boost=/usr/local/boost --with-libevent=/usr/loc
阅读全文
摘要:直接执行即可,执行前需要确保机器上的 wget、gunzip、bunzip2、cmake 可用。 一键编译和安装 gcc 脚本:[install_gcc_tool.sh](https://github.com/eyjian/libmooon/blob/master/shell/install_gcc
阅读全文
摘要:使用 mpc-1.3.0 编译 gcc-13.1.0,执行 gcc 的 configure 时遇到如下错误: ``` checking for the correct version of gmp.h... yes checking for the correct version of mpfr.h
阅读全文
摘要:-D_GLIBCXX_DEBUG 编译时,指定宏 _GLIBCXX_DEBUG 即以 Debug 方式使用 STL 库,效果如下: #include <string> #include <stdio.h> int main(int argc, char* argv[]) { std::string
阅读全文
摘要:编译命令: ./configure --prefix=/usr/local/thrift-0.14.2 --with-cpp=yes --with-php=no --with-python=no --with-qt5=no --with-c_glib=no --with-java=no --with
阅读全文
摘要:本文限定为主动从配置中心读取配置方法,不限定配置中心类型,比如可使用DB作为配置中心。 程序和配置中心间存在网络开销,因此需避免每次业务处理或请求都从配置中心读取配置。 规避网络开销,可采取本地缓存配置,每隔指定时间只读取一次配置中心,比如每秒读取一次配置中心。 假设每秒读取一次配置中心,这样每次的
阅读全文
摘要:// C++20新线程 jthread 体验代码 // // 编译(编译本代码,-pedantic 不是必须的): // g++ -std=c++20 -Wall -pedantic -pthread -static-libstdc++ C++20_jthread.cpp -o C++20_jthr
阅读全文
摘要:目录 目录 1 1. 引言 1 2. 少为人知的符号表1 1 2.1. 符号表 1 2.2. 代码示例 2 3. 少为人知的符号表2 2 3.1. 符号表 2 3.2. 代码示例 3 附:C++的59个关键词列表 3 1. 引言 这些鲜为人知的C++符号,可直接在代码中使用,但实践中不推荐这么做,可
阅读全文
摘要:`static __thread off_t dirsize; // 目录大小 static int _du_fn(const char *fpath, const struct stat *sb, int typeflag) { if (FTW_F == typeflag) dirsize +=
阅读全文
摘要:目的:简化使用,比如省去了读取配置或者代码中直接大段难以维护的定义。 常用场景:Schema、Lua、SQL等 Linux 自带了资源编译工具 xxd,可将任意文件编译成 c 源代码文件。 常用命令格式: |xxd -i 源文件 目标文件| |--|--| CMake应用示例1(将 test.lua
阅读全文
摘要:首先,下载 gRPC 源代码到本地: git clone https://github.com/grpc/grpc.git 如果只想下载指定版本的,如以版本“1.27.3”为例,可改成如下语句: git clone b v1.27.3 https://github.com/grpc/grpc.git
阅读全文
摘要:在Linux上执行“man raise”,即可看到两者的区别: 函数raise 函数kill 函数性质 LIBC库函数, raise基于系统调用kill或tgkill(如果内核支持)实现 系统调用,不是LIBC库函数 单线程程序 raise(sig)效果等同kill(getpid(), sig) 多
阅读全文
摘要:下列错误,可能是因为在64位上跑32位程序: Value too large for defined data type 此错误对应的出错代码为EOVERFLOW,原因可能是目标文件超过2GB大小。 下列代码可能会导致这个错误出错(为何说是可能,本节最后部分解释): // g++ -g -o x x
阅读全文
摘要:目录 目录 1 1. 库函数fflush原型 1 2. FILE结构体 1 3. fflush函数实现 2 4. fclose函数实现 4 附1:强弱函数名 5 附2:属性__visibility__ 6 1. 库函数fflush原型 先瞧瞧fflush的原型: #include <stdio.h>
阅读全文
摘要:先抓出std::endl的源代码: /** * @file ostream * @brief Write a newline and flush the stream. * * This manipulator is often mistakenly used when a simple newli
阅读全文
摘要:一线上CGI偶发性会报“资源访问错误”,经过分析得出是因为CgiHost没有读取到CGI的任务输出,即CGI运行完成后连HTTP头都没有一点输出。 然而实际上,不可能没有任何输出,因为CGI至少有无条件的HTTP头部分输出,因此问题是输出丢失了。CGI和CgiHost间是通过重定向CGI的标准输出到
阅读全文
摘要:一小伙说他的程序死锁了,让帮忙看看。对死锁问题,首先祭出GDB这一神器。 (gdb) bt #0 0xffffe410 in __kernel_vsyscall () #1 0xf7fa790e in __lll_mutex_lock_wait () from /lib/libpthread.so.
阅读全文