随笔分类 -  C_CPP

摘要:// 段错误捕获,并打印栈信息 static void segvhandler(int sig) { #define BACKTRACE_MAX_FRAMES 100 static bool in_handler = false; printf("capture a signal: %d", sig 阅读全文
posted @ 2018-05-12 15:54 yuxi_o 阅读(482) 评论(0) 推荐(0)
摘要:一. 查看栈大小限制 不同系统的栈空间大小不同,可通过如下方法查看系统栈大小限制 cat /proc/1/limits 该文件列出了系统资源限制情况(ubuntu 16.04): 可知该系统中栈空间大小限制为8M。 二. 超过栈大小后段错误 三. 解决方案 对于超出栈大小的内存申请采用malloc或 阅读全文
posted @ 2018-05-12 11:27 yuxi_o 阅读(4953) 评论(0) 推荐(1)
摘要:一、数组初始化 1.1 格式 共两种格式: char buf[32] = {0}; int buf[32] = {0}; 适用于所有类型。 char buf[32] = ""; 仅适用于char,相当于定义一个‘\0’的空串。 1.2 初始化为0 数组初始化为0的方法有如下三种: 1. 全局变量和静 阅读全文
posted @ 2018-05-12 10:45 yuxi_o 阅读(1403) 评论(0) 推荐(0)
摘要:glibc源码:http://ftp.gnu.org/gnu/glibc/ 移植glibc到riscv架构 Newlib移植 C标准 阅读全文
posted @ 2018-01-04 22:51 yuxi_o 阅读(366) 评论(0) 推荐(0)
摘要:poll同select,用于监控file descriptor事件,推荐用poll的升级版epool来实现功能,但在简单应用中使用poll更方便。 fds是文件描述符集的数组,nfds指定数组元素个数。 pollfd中fd是打开文件的文件描述符;events是输入参数,指定监控事件;revents是 阅读全文
posted @ 2018-01-02 23:20 yuxi_o 阅读(294) 评论(0) 推荐(0)
摘要:所谓“条件编译”,是对部分内容指定编译的条件,使其只在满足一定条件才进行编译。 常用形式 多条件编译 常用格式 示例 执行结果: 常见的预处理指令 参考: C/C++预处理指令#define,#ifdef,#ifndef,#endif… 阅读全文
posted @ 2017-10-14 17:44 yuxi_o 阅读(347) 评论(0) 推荐(0)
摘要:C语言中 typeof 关键字是用来定义变量数据类型的。在linux内核源代码中广泛使用。 使用方法 1.当x的类型为是 int 时 _min1变量的数据类型则为 int。 2.当x为一个表达式时(例: x = 3-4), _min1变量的数据类型为这个表达式结果的数据类型。 3. typeof括号 阅读全文
posted @ 2017-09-07 22:45 yuxi_o 阅读(676) 评论(0) 推荐(0)
摘要:getopt解析命令行选项 getopt, getopt_long, getopt_long_only, optarg, optind, opterr, optopt - Parse command-line options 其中argc和argv等同于main函数参数。 命令行选项元素(an op 阅读全文
posted @ 2017-09-03 22:01 yuxi_o 阅读(360) 评论(0) 推荐(0)
摘要:man tzset可以很清楚了解时区设置格式,共3种: The first format is used when there is no daylight saving time in the local timezone: std offset The second format is used 阅读全文
posted @ 2017-06-27 23:59 yuxi_o 阅读(4091) 评论(0) 推荐(0)
摘要:linux中应用层(非内核层)time是怎样处理的?时区是怎样设置的?夏令时时是怎样实现的?NTP时间同步是怎么回事?本篇文章就在嵌入式linux应用中time和timezone相关问题总结。 1. NTP 经常说时间同步,同步就是为了获取统一的时间参考点。同步的时间来自授时中心,如ntp.pool 阅读全文
posted @ 2017-06-27 23:01 yuxi_o 阅读(9312) 评论(0) 推荐(0)
摘要:glibc中的malloc实现: The main properties of the algorithms are:* For large (>= 512 bytes) requests, it is a pure best-fit allocator, with ties normally de 阅读全文
posted @ 2017-06-18 10:53 yuxi_o 阅读(1887) 评论(0) 推荐(1)
摘要:语法 解析 The glob() function searches for all the pathnames matching pattern according to the rules used by the shell (see glob(7)). glob()用于搜索路径下所有匹配的文件 阅读全文
posted @ 2017-06-11 22:18 yuxi_o 阅读(1120) 评论(0) 推荐(0)
摘要:语法 解析 正则表达式库函数主要分两部分,正则表达式编译和匹配。编译用于正则表达式提供格式(程序识别),匹配用于提供匹配位置便于提取。 regcomp() is used to compile a regular expression into a form that is suitable for 阅读全文
posted @ 2017-06-11 22:14 yuxi_o 阅读(768) 评论(0) 推荐(0)
摘要:在linux内核中重新定义了printk,如pr_debug,dev_dbg等。要使用这些宏函数就需要定义DEBUG。 详见:kernel printk信息显示级别 那么DEBUG该定义在什么地方呢? 定义到pr_debug或dev_dbg头文件中,则内核所有的宏都起作用。则打印信息太多,不易调试。 阅读全文
posted @ 2017-03-16 21:56 yuxi_o 阅读(711) 评论(0) 推荐(0)
摘要:strtok,strtok_r,strsep--extract tokens from strings Tje strsep() function was introduced as a replacement for strtok, since the latter cannot handle e 阅读全文
posted @ 2016-11-27 21:53 yuxi_o 阅读(491) 评论(0) 推荐(0)
摘要:1. struct中函数 结构体中函数占用字节数:32位主机占用4个字节,64位主机占用8个字节。 结构体中函数本质是指针,占用字节数与指针相同。 #include <stdio.h> struct student_st { char name[20]; int no; void (*show)(s 阅读全文
posted @ 2016-11-21 00:25 yuxi_o 阅读(728) 评论(0) 推荐(0)
摘要:随机数产生推荐用random(),在产生随机数前要添加种子srandom((unsigned int)time(NULL))。 SYNOPSIS #include <stdlib.h> long int random(void); void srandom(unsigned int seed); 旧 阅读全文
posted @ 2016-11-20 22:14 yuxi_o 阅读(198) 评论(0) 推荐(0)
摘要:一. PC编译安装boost boost是C++的准标准库,其有两种安装方法。 1. ubuntu下,通过sudo apt-get install libboost-all-dev。 2. 通过源码包安装,http://sourceforge.net/projects/boost/files/lat 阅读全文
posted @ 2016-11-13 18:09 yuxi_o 阅读(2591) 评论(0) 推荐(0)
摘要:1. offsetof #include <stddef.h> size_t offsetof(type, member); The macro offsetof() returns the offset of the field member from the start of the struc 阅读全文
posted @ 2016-11-07 22:22 yuxi_o 阅读(207) 评论(0) 推荐(0)
摘要:mosquitto提供了一个参考示例: void mosquitto__daemonise(void) { #ifndef WIN32 char *err; pid_t pid; pid = fork(); if(pid < 0){ err = strerror(errno); log__print 阅读全文
posted @ 2016-10-31 21:45 yuxi_o 阅读(221) 评论(0) 推荐(0)