岚天逸见

随笔分类 -  C/C++

1 2 3 4 5 ··· 12 下一页

取得std::ifstream对象的文件描述符
摘要:使用C++标准库无法取得std::ifstream对象的文件描述符,但GNU libstdc++库可以取得: #include <fstream> #include <iostream> #include <ext/stdio_filebuf.h> int main() { std::ifstrea 阅读全文

posted @ 2023-09-05 14:18 岚天逸见 阅读(45) 评论(0) 推荐(0) 编辑

chatGPT用C++写的HMAC-SHA256函数
摘要:以下内容全为 chatGPT 生成: ```cpp #include #include #include #include std::string hmac_sha256(const std::string &key, const std::string &data) { unsigned char 阅读全文

posted @ 2023-08-15 15:58 岚天逸见 阅读(276) 评论(0) 推荐(0) 编辑

C++不同标准兼容性问题集
摘要:* **特化模板兼容性** 下列代码在 c++17 及之前都是可以的,但从 c++20 开始编译报语法错误: ```cpp // g++ -g -std=c++20 -o x x.cpp;./x #include #include template struct X { X(type t) { th 阅读全文

posted @ 2023-07-27 09:42 岚天逸见 阅读(60) 评论(0) 推荐(0) 编辑

使用gcc-13.1.0编译安装thrift-0.18.1
摘要:执行 configure 生成 Makefile,排除掉不需要的语言支持和测试等: ```bash ./configure --prefix=/usr/local/thrift-0.18.1 --with-boost=/usr/local/boost --with-libevent=/usr/loc 阅读全文

posted @ 2023-07-25 17:07 岚天逸见 阅读(54) 评论(0) 推荐(0) 编辑

一键编译和安装 gcc 脚本
摘要:直接执行即可,执行前需要确保机器上的 wget、gunzip、bunzip2、cmake 可用。 一键编译和安装 gcc 脚本:[install_gcc_tool.sh](https://github.com/eyjian/libmooon/blob/master/shell/install_gcc 阅读全文

posted @ 2023-07-24 19:29 岚天逸见 阅读(123) 评论(0) 推荐(0) 编辑

mpc库问题导致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 阅读全文

posted @ 2023-07-24 15:24 岚天逸见 阅读(376) 评论(0) 推荐(0) 编辑

debug方式使用stl
摘要:-D_GLIBCXX_DEBUG 编译时,指定宏 _GLIBCXX_DEBUG 即以 Debug 方式使用 STL 库,效果如下: #include <string> #include <stdio.h> int main(int argc, char* argv[]) { std::string 阅读全文

posted @ 2022-04-25 11:39 岚天逸见 阅读(291) 评论(0) 推荐(0) 编辑

编译 thrift-0.14.2 的 C++ 版本
摘要:编译命令: ./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 阅读全文

posted @ 2021-09-05 09:54 岚天逸见 阅读(235) 评论(0) 推荐(0) 编辑

多线程程序如何简单高效地读取配置中心上的配置?
摘要:本文限定为主动从配置中心读取配置方法,不限定配置中心类型,比如可使用DB作为配置中心。 程序和配置中心间存在网络开销,因此需避免每次业务处理或请求都从配置中心读取配置。 规避网络开销,可采取本地缓存配置,每隔指定时间只读取一次配置中心,比如每秒读取一次配置中心。 假设每秒读取一次配置中心,这样每次的 阅读全文

posted @ 2020-12-18 15:54 岚天逸见 阅读(139) 评论(0) 推荐(0) 编辑

C++20新线程 jthread 体验代码
摘要:// C++20新线程 jthread 体验代码 // // 编译(编译本代码,-pedantic 不是必须的): // g++ -std=c++20 -Wall -pedantic -pthread -static-libstdc++ C++20_jthread.cpp -o C++20_jthr 阅读全文

posted @ 2020-09-09 15:20 岚天逸见 阅读(895) 评论(0) 推荐(0) 编辑

C++鲜为人知的符号
摘要:目录 目录 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++符号,可直接在代码中使用,但实践中不推荐这么做,可 阅读全文

posted @ 2020-07-20 20:27 岚天逸见 阅读(453) 评论(0) 推荐(0) 编辑

获取指定目录大小函数源码
摘要:`static __thread off_t dirsize; // 目录大小 static int _du_fn(const char *fpath, const struct stat *sb, int typeflag) { if (FTW_F == typeflag) dirsize += 阅读全文

posted @ 2020-07-20 17:28 岚天逸见 阅读(170) 评论(0) 推荐(0) 编辑

将资源文件编译成源代码文件
摘要:目的:简化使用,比如省去了读取配置或者代码中直接大段难以维护的定义。 常用场景:Schema、Lua、SQL等 Linux 自带了资源编译工具 xxd,可将任意文件编译成 c 源代码文件。 常用命令格式: |xxd -i 源文件 目标文件| |--|--| CMake应用示例1(将 test.lua 阅读全文

posted @ 2020-07-20 17:22 岚天逸见 阅读(446) 评论(0) 推荐(0) 编辑

CMake 方式编译 gRPC
摘要:首先,下载 gRPC 源代码到本地: git clone https://github.com/grpc/grpc.git 如果只想下载指定版本的,如以版本“1.27.3”为例,可改成如下语句: git clone b v1.27.3 https://github.com/grpc/grpc.git 阅读全文

posted @ 2020-04-01 12:11 岚天逸见 阅读(3397) 评论(1) 推荐(1) 编辑

C程序中的raise和kill两个函数有何不同?
摘要:在Linux上执行“man raise”,即可看到两者的区别: 函数raise 函数kill 函数性质 LIBC库函数, raise基于系统调用kill或tgkill(如果内核支持)实现 系统调用,不是LIBC库函数 单线程程序 raise(sig)效果等同kill(getpid(), sig) 多 阅读全文

posted @ 2020-01-16 14:34 岚天逸见 阅读(833) 评论(0) 推荐(0) 编辑

运行程序时报错“Value too large for defined data type”
摘要:下列错误,可能是因为在64位上跑32位程序: Value too large for defined data type 此错误对应的出错代码为EOVERFLOW,原因可能是目标文件超过2GB大小。 下列代码可能会导致这个错误出错(为何说是可能,本节最后部分解释): // g++ -g -o x x 阅读全文

posted @ 2020-01-13 15:34 岚天逸见 阅读(3537) 评论(0) 推荐(0) 编辑

GLIBC中的库函数fflush究竟做了什么?
摘要:目录 目录 1 1. 库函数fflush原型 1 2. FILE结构体 1 3. fflush函数实现 2 4. fclose函数实现 4 附1:强弱函数名 5 附2:属性__visibility__ 6 1. 库函数fflush原型 先瞧瞧fflush的原型: #include <stdio.h> 阅读全文

posted @ 2019-11-14 12:48 岚天逸见 阅读(1227) 评论(0) 推荐(0) 编辑

C++标准库中的std::endl究竟做了什么?
摘要:先抓出std::endl的源代码: /** * @file ostream * @brief Write a newline and flush the stream. * * This manipulator is often mistakenly used when a simple newli 阅读全文

posted @ 2019-11-13 16:15 岚天逸见 阅读(2824) 评论(0) 推荐(0) 编辑

C++ CGI报“资源访问错误”问题分析
摘要:一线上CGI偶发性会报“资源访问错误”,经过分析得出是因为CgiHost没有读取到CGI的任务输出,即CGI运行完成后连HTTP头都没有一点输出。 然而实际上,不可能没有任何输出,因为CGI至少有无条件的HTTP头部分输出,因此问题是输出丢失了。CGI和CgiHost间是通过重定向CGI的标准输出到 阅读全文

posted @ 2019-11-08 10:45 岚天逸见 阅读(653) 评论(0) 推荐(0) 编辑

一个死锁分析过程
摘要:一小伙说他的程序死锁了,让帮忙看看。对死锁问题,首先祭出GDB这一神器。 (gdb) bt #0 0xffffe410 in __kernel_vsyscall () #1 0xf7fa790e in __lll_mutex_lock_wait () from /lib/libpthread.so. 阅读全文

posted @ 2019-09-08 16:30 岚天逸见 阅读(340) 评论(0) 推荐(0) 编辑

1 2 3 4 5 ··· 12 下一页

导航

统计信息

点击右上角即可分享
微信分享提示