C常用代码
一、批量转移字符到缓冲区
bufptr = buffer;
void bufwrite(char* p,int n)
{
while(n>0)
{
int k,rem;
if(bufptr == &buffer[N])
flushbuffer();
rem = N - (bufptr - buffer);
k = n > rem ? rem : n;
memcpy(bufptr,p,k);
bufptr += k;
p += k;
n -= k;
}
}
二、移位运算符
有符号整数的向右移位运算也不等于除以2的某次幂。 如: (-1)>> 1 一般不等于0,而 (-1)/2在大多数C实现上求值结果为0.
相关文档:
extern "C"
extern "C" 包含双重含义,从字面上即可得到:首先,被它修饰的目标是“extern”的;其次,被它修饰的目标是“C”的。让我们来详细解读这两重含义。
(1) 被extern "C"限定的函数或变量是extern类型的;
extern是C/C++语言中表 ......
The meaning of the c in calloc was vividly discussed in comp.lang.c in October 2000 (see here), with both clear (because, unlike malloc, calloc clears the memory it returns) and count (because, unlike malloc, calloc is passed a count of elements to allocate) suggested as possible explanations, howev ......
目的:当程序在前台运行时,按挂机键程序不退出,只是退到后台运行,程序在后台运行时,按c键能把程序结束
方法:在HandleWsEventL()中屏蔽挂机键KAknUidValueEndKeyCloseEvent,在值在avkon.hrh中定义,实践中发现8.0sdk的avkon.hrh没有定义KAknUidValueEndKeyCloseEvent,唯有手工添加定义#define KAknUidValueEndK ......
众所周知,strcmp为字串比较只用,简单的函数并不简单。
下面的代码
int main()
{
char* cp1 = {'z', 'h', 'a', 'n', 'g'};
char* cp2 = {'z', 'h', 'a', 'n', 'g'};
std::cout<<strcmp(cp1, cp2)<< ......
内存控制篇
calloc
free
getpagesize
malloc
mmap
munmap
calloc(配置内存空间)
相关函数
malloc,free,realloc,brk
表头文件
#include <stdlib.h>
定义函数
void *calloc(size_t nmemb,size_t size);
函数说明
calloc()用来配置nmemb个相邻的内存单位,每一单位的大小为size,并返回指向第 ......