- 博客(16)
- 资源 (2)
- 收藏
- 关注
原创 setjump 和 longjump实践
今天单步跑了一下APUE中setjump/longjump的例子,单步跟踪了下程序的执行流程。体会是如果注释掉exit(0)之后,整个程序变成了一个无限死循环。#include <setjmp.h>static void f1(int, int, int, int);static void f2(void);static jmp_buf jmpbuffer;static...
2018-03-30 10:17:37 1410
原创 read和fread以及write和fwrite的差别
两组函数的差别从名字就可以看出来,主要还是实现方式的不同。 fread和fwrite是经过系统一层操作,而文件系统一般是块设备,会对数据进行缓存,然后最终会调用的read和write。read和write是基于设备的操作,无文件系统缓存,是最底层的IO。 下图展示了两组函数的区别。 由于实现方式的不同,性能和使用场合都不同。...
2018-03-28 16:35:27 1740 1
原创 ctors,dtors,_ctors&_dtors
/* ctors and dtors arrays -- to be used by runtime system *//* to call static constructors and destructors *//* *//* NOTE: Use a C ...
2018-03-27 15:36:49 2988
原创 bool 和_Bool , bool & _Bool
bool是C++的关键字,一种数据类型,长度是4!!! _Bool是C99新增加的关键字,长度是1, 在C++中,又把bool重定义为_Bool ,typedef bool _Bool;void l_Bool(void){ printf("sizeof(_Bool) is %d\n",sizeof(_Bool));}void lbool(void){ pri...
2018-03-26 16:24:03 13818 2
原创 移植LUA到VxWorks的步骤
1)建立VxWorks DKM工程 2)导入LUA源代码 3)修改lprefix.h/*** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $** Definitions for Lua code that must come before any other header file** See Copyright No...
2018-03-26 12:48:32 715
原创 GCC内联汇编(inline assembly )的几个例子
https://gcc.gnu.org/onlinedocs/gcc/index.html#SEC_Contentsint __ffs (int x){ int cnt; int tmp; asm ("bsfl %2,%0\n" /* Count low bits in X and store in %1. */ "cmovel %1,%0\n"...
2018-03-22 10:40:54 1571
原创 realloc函数,内存再分配
realloc是C库提供的函数,用于动态分配新的内存地址,其原型是: void* realloc (void* ptr, size_t size); ptr:由malloc,calloc或realloc分配的地址 size:需要申请内存大小,单位为byte当ptr==NULL时,realloc作用和malloc一样当newSize》size时,realloc可能在原有内存的地址处扩展...
2018-03-19 16:02:33 401
原创 GCC中MAX和MIN的安全定义
#define MAX(a,b) ({ typeof(a) _a = (a); typeof(b) _b = (b); \ _a > _b ? _a : _b; })#define MIN(a,b) ({ typeof(a) _a = (a); typeof(b) _b = (b); \ _a < _b ? ...
2018-03-16 15:09:44 1250
原创 数据结构:单向链表的C语言实现
头文件typedef struct _slnode{ struct _slnode *pNext;}SL_NODE;typedef struct slLIST{ SL_NODE *head; SL_NODE *tail; int count;}SLL;typedef struct _sl_data{ SL_NODE nod...
2018-03-14 15:13:48 226
原创 code review checklist
1)general :compiler version,flag,os 2)copyright,date,version,author,modification history 3)comments format 4)variable,data structure 5)function 6)0 error,0 warning 7)preprocessor 8)memory manag...
2018-03-13 09:45:39 448
原创 一个哈希表Hash Table的例子,用于IPv4协议的IP地址查找
头文件typedef struct ip4_addr_key{ unsigned int ifindex; unsigned int addr; unsigned short vr;}ip4AddrKey;typedef unsigned int (*hash_obj)(...
2018-03-13 09:38:00 1542
原创 用offsetof 计算成员变量的偏移,用member_to_object获取容器对象基址
用过Linux的程序员都知道,Linux提供了一个宏函数,可以根据成员变量的地址计算父对象的地址 宏函数的定义如下:define container_of(ptr, type, member) ({ \const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type )( (char )__mptr - ...
2018-03-07 11:15:45 635
原创 ARM平台上VxWorks任务栈的使用
int f2(int a,int b) {int ret;int lla=0x55;int llb=0x33;ret=a+b;return ret;} 一个非常简单的C函数,主要用来说明参数和局部变量在堆栈里的分配,入栈操作看明白了,但出栈操作看不明白!-> l 0x00203470 f2: 00203470 e1a0c00d MOV...
2018-03-06 10:37:46 1387
原创 ARM指令寻址模式,内存访问3种格式
ARM指令的三种寻址模式: 1)基址偏移LDR R1,[R2,#-0x10]2)基址偏移前变址LDR R1,[R2,#-0x10]! // R1 =*(R2-0x10),R2=R2-0x103)基址偏移后变址LDR R1,[R2],#-0x10 // R1 =*(R2),R2=R2-0x10;A8.5 Memory accesses Commonly, the fo...
2018-03-06 10:08:22 1810
原创 各种const 修饰
const int a=1; int c=2const int *p=&c; int *const pp=&a;a=2;//error ,read-only variable; *p=3;//error, read-only (memory)location, but c=5 is OK;pp=&c;//error,assignment of read-o...
2018-03-01 15:50:45 113
原创 零拷贝接收函数
includeincludeincludeincludeinclude”sockLib.h”include “stdio.h”include “stdlib.h”include “string.h”include “cq.h”include “udpServer.h”struct sockaddr_in serverAddr1; str...
2018-03-01 15:16:02 422
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人