
c
lwj1396
这个作者很懒,什么都没留下…
展开
-
引用局部变量地址
#include "stdio.h"int *p = NULL;int *fFun(void){int i = 0;//i要被销毁掉,i的值为多少没有关系。return &i;}void subFun(void){(*p)--;}void gFun(void){int j;for(j = 0;j<10;j++){s原创 2008-07-14 21:12:00 · 3818 阅读 · 0 评论 -
在python中嵌入c/c++
学习python是一个令人振奋不已的过程,python是一个如此powerfull的高级语言,简单却功能强大,库多而又功能齐全,几乎可以帮助我们完成任何一项工作。它唯一的缺陷就是跑得慢,在跑得慢的问题上,它有有着令人振奋的解决方案,嵌入c/c++代码的方法。一个程序80%的时间运行在20%的代码上,我们只要用c重写那20%的代码,便可缔造完美程序。 除了运行速度问题,还有其他可以用c来增原创 2008-12-16 12:31:00 · 9449 阅读 · 0 评论 -
c++ 测试篇
作者:CppExplore 网址:http://www.cppblog.com/CppExplore/在c++的世界里,程序设计的优雅让位于程序的稳定性、健壮性。“好程序是测出来的”这句话在C++领域里得到了充分体现。下面是我在开发中使用的测试方法,抛砖引玉,和大家交流下。测试期间,关闭对core文件的限制,使用命令:ulimit -c unlimited(1)开发阶段,使用cppunit维护转载 2008-12-24 11:04:00 · 2645 阅读 · 0 评论 -
线程
作者:CppExplore 网址:http://www.cppblog.com/CppExplore/废话不多说,详细介绍使用线程的优点好处请参考baidu、google。一、线程使用场景。使用线程的方式大致有两种:(1)流水线方式。根据业务特点,将一个流程的处理分割成多个线程,形成流水线的处理方式。产生的结果:延长单一流程的处理时间,提高系统整体的吞吐能力。(2)线程池方式。针对处理时间比较长且转载 2008-12-24 11:45:00 · 1566 阅读 · 0 评论 -
数值型打印二进制数据
#include #include int main(){ long number=2; char string[25]; itoa(number,string,2/*这里是进位制,可以是任意的,2就是二进制了*/); printf("integer=%d string=%s",number,string); getchar(); return 0;}原创 2009-06-28 17:01:00 · 713 阅读 · 0 评论 -
用rand()和srand()产生为随机数的方法总结
标准库(被包含于中)提供两个帮助生成伪随机数的函数: 函数一:int rand(void);从srand (seed)中指定的seed开始,返回一个[seed, RAND_MAX(0x7fff))间的随机整数。 函数二:void srand(unsigned seed);参数seed是rand()的种子,用来初始化rand()的起始值。 可以认为rand()在每次被调用的时候,它会查看转载 2009-06-28 09:23:00 · 1516 阅读 · 2 评论 -
很好的技术文件集合
C Introduction to C Programming C Optimization Tutorial Compiling C and C++ Programs on UNIX Systems - gcc/g++ Building and Using Static and Shared C Libraries Programming in C: UNIX System Calls and原创 2009-11-20 14:12:00 · 5173 阅读 · 10 评论 -
dlopen加载c++ 函数及类
问题所在 有时你想在运行时加载一个库(并使用其中的函数),这在你为你的程序写一些插件或模块架构的时候经常发生。 在C语言中,加载一个库轻而易举(调用dlopen、dlsym和dlclose就够了),但对C++来说,情况稍微复杂。动态加载一个C++库的困难一部分是因为C++的name mangling(译者注:也有人把它翻译为“名字毁坏”,我觉得还是不翻译好),另一部分是因为dl转载 2010-01-17 21:13:00 · 13447 阅读 · 1 评论 -
(转)使用C/C++扩展Python
使用C/C++扩展Python翻译:gashero如果你会用C,实现Python嵌入模块很简单。利用扩展模块可做很多Python不方便做的事情,他们可以直接调用C库和系统调用。为了支持扩展,Python API定义了一系列函数、宏和变量,提供了对Python运行时系统的访问支持。Python的C API由C源码组成,并包含 “Pyth转载 2009-12-02 14:50:00 · 4030 阅读 · 0 评论 -
(转)用GDB调试程序
用GDB调试程序GDB是一个强大的命令行调试工具。大家知道命令行的强大就是在于,其可以形成执行序列,形成脚本。UNIX下的软件全是命令行的,这给程序开发提代供了极大的便利,命令行软件的优势在于,它们可以非常容易的集成在一起,使用几个简单的已有工具的命令,就可以做出一个非常强大的功能。于是UNIX下的软件比Windows下的软件更能有机地结合,各自发挥各自的长处,组合成更为强劲的功能。而转载 2009-12-02 16:24:00 · 900 阅读 · 0 评论 -
(转)C语言家族扩展
翻译:5.1--5.6林峰5.7--5.20董溥5.21--5.26王聪5.27--5.34刘洋5.35--5.43贾孟树致谢:感谢陈老师指出其中的一些错误,已修订。修订记录: 修订一些用词和标点符号。(董溥)2007年1月12号修转载 2009-12-02 16:35:00 · 1695 阅读 · 1 评论 -
fork vfork exit _exit
fork: 子进程拥有父进程的数据段、堆和栈的副本,父进程和子进程共享正文段。但现在很多实现却并不是将父进程的数据段、堆栈段进行完全拷贝,而是采用写时复制(copy-on-write),内核将其标记为只读,(典型的页式虚存)只有父进程或子进程对这些区域进行修改时内核才真正将那一页进行拷贝,从物理上分离开。 vfork:由于在vfork后经常是跟着一个exec执行一个新的程序不会在用到原来的地址转载 2010-03-12 09:48:00 · 1181 阅读 · 0 评论 -
int2float
// =====================================================================================// // Filename: int2float.c// // Description: int和float转换时,内存是如何变的,gdb x调试// // Ve原创 2010-05-08 15:03:00 · 1430 阅读 · 0 评论 -
compute the MAX and MIN of int
int max=(int)(((unsigned int)~0)>>1);int min=(int)((unsigned int)~max);printf("max=%d,min=%d/n",max,min);short maxs=(short)(((unsigned short)~0)>>1);short mins=(short)((unsigned short)~maxs);原创 2010-05-31 10:52:00 · 1048 阅读 · 0 评论 -
中途需要产生const变量的一些方法
<br />需求:<br />int c =0;<br />// the value of c is initialized here<br />switch(someVar){<br /> case foo: c =3;break;<br /> case bar: c =4;break;<br /> default: c =42;// what else?<br />}<br />// now c is constant<br />ASSUME_CONST_FROM_NOW(c)// 中途产生翻译 2011-01-14 19:15:00 · 910 阅读 · 0 评论 -
iOS要点散记
KCFStringEncodingGB_18030_2000 gbk/gb2321KCFStringEncodingISOLatin1 iso-8559-1wchar_t 在mac下是4个字节,在linux下是2个。。。原创 2012-10-23 19:23:20 · 830 阅读 · 0 评论 -
c99 学习笔记
/ =====================================================================================// // Filename: char.c// // Description: char size test// // Version: 1.0// Crea原创 2013-03-17 21:44:41 · 1116 阅读 · 0 评论 -
现在c语言都这样写了么
//// main.c// ctest//// Created by liweijian on 13-3-18.// Copyright (c) 2013年 liweijian. All rights reserved.//#include #include //闭包typedef void(*func_t)();func_t test(){ void原创 2013-03-18 14:13:24 · 1131 阅读 · 0 评论 -
背包问题
此处背包问题描述为:N种大小和价值不等东西,容量为M的背包,求能带走的最大价值。 可以采用直接递归做法,但是时间复杂度为指数级别,代码如下 //递归版本,指数复杂度,cap为容量int knap(int cap){ int i,t,max,space; for(i=0,max=0;i<N;i++) if((space=cap-ite原创 2009-01-16 16:58:00 · 931 阅读 · 0 评论 -
约瑟夫环
数组实现链表:#include#include#define N 8#define M 5int item[N];int next[N];void init(){ int i; for(i=0;i<N;i++) { item[i]=i; next[i]=i+1; }原创 2009-01-14 13:05:00 · 809 阅读 · 0 评论 -
plan
原创 2009-01-02 14:11:00 · 1158 阅读 · 0 评论 -
移位操作
(1)unsigned char x=3; x>1是多少? (2)char x=3; x>1是多少? (3)char x=-3; x>1是多少? 3写成二进制数是00000011;-3写成二进制数是(补码)11111101。 程序执行的时候,操作的是数值的编码表示,也就是数值在内存中的二进制表示。比如说,程序取-3的时候,就去取1111110转载 2008-07-15 10:13:00 · 3685 阅读 · 0 评论 -
位运算
在计算机程序中,数据的位是可以操作的最小数据单位,理论上可以用“位运算”来完成所有的运算和操作。一般的位操作是用来控制硬件的,或者做数据变换使用,但是,灵活的位操作可以有效地提高程序运行的效率。C语言提供了位运算的功能, 这使得C语言也能像汇编语言一样用来编写系统程序。 位运算符C语言提供了六种位运算符: & 按位与 | 按位或 ^ 按位异或 ~ 取反 >> 右移转载 2008-07-23 11:31:00 · 3987 阅读 · 0 评论 -
htoi函数
#include#include/* 方案一,模拟KR书本的atoiint hexalpha_to_int(int c){ char hexalpha[] = "aAbBcCdDeEfF"; int i; int answer=0; for(i=0;answer==0&&hexalpha[i]!=/0;i++) if(hexalpha[i]==c原创 2008-07-23 11:35:00 · 12532 阅读 · 0 评论 -
c F&A
The questions answered here are divided into several categories: 1. Declarations and Initializations 2. Structures, Unions, and Enumerations 3. Expressions 4. Pointers 5. Null Pointers 6. Array转载 2008-07-21 10:13:00 · 8180 阅读 · 0 评论 -
中文字符
#include#include#includeint main(){ //char *a=(char*)malloc(100*sizeof(char)); char c; char a[100]; int i=0; while((c=getchar())!=EOF) { a[i++]=c; } a[i]=/0; i=0;原创 2008-07-25 10:46:00 · 3793 阅读 · 0 评论 -
内存调试系列
http://www.ibm.com/developerworks/cn/linux/l-cn-memleak/index.htmlhttp://www.ibm.com/developerworks/cn/aix/library/au-memorytechniques.html转载 2008-07-25 11:53:00 · 3780 阅读 · 0 评论 -
tableau problem
Problem 1: Young tableauAn m × n Young tableau is an m × n matrix such that the entries of each row are in sorted orderfrom left to right and the entries of each column are in sorted order from top to原创 2008-07-27 15:45:00 · 3933 阅读 · 0 评论 -
gcc编译程序崩溃了!
程序如下:#includevoid escape(char *s,char *t){ char *toend=s; while(toend!=/0) toend++;//to the end of source while(t!=/0) { switch(*t) { case /t:原创 2008-07-24 12:10:00 · 4616 阅读 · 4 评论 -
堆排序(1)
Analyzing the course,There are 2 points must to be take care: 1 : max_heapify() cost O(lgn) time,build_heap cost O(n).so we can say that the total runing time is O(nlgn). But is not a tigh原创 2008-07-25 11:13:00 · 3785 阅读 · 0 评论 -
程序的链接和装入及Linux下动态链接的实现
http://www.ibm.com/developerworks/cn/linux/l-dynlink/index.html#N1014C转载 2008-07-25 11:36:00 · 4038 阅读 · 0 评论 -
快速排序
#includevoid swap(int *a, int *b){ int temp=*a; *a=*b; *b=temp;}int partition(int a[],int low,int high){ int i=low-1; int j=low; for(;j { if(a[j]>=a[high]) {原创 2008-07-29 10:04:00 · 4017 阅读 · 1 评论 -
查看你可以分配多少内存
int MB=0; while(malloc(1原创 2008-07-29 10:15:00 · 3913 阅读 · 0 评论 -
counting sort(stable)
#include#includevoid counting_sort(int a[], int sorted[],int k,int size){ int *c=(int *)malloc((k+1)*sizeof(int)); int i=0; for(;i c[i]=0; for(i=0;i c[a[i]]=c[a[i]]+1; //n原创 2008-08-01 09:20:00 · 3926 阅读 · 0 评论 -
itob
#include#include#includevoid itob(int n,char s[],int b);void reverse(char s[]);void reverse(char s[]){ int i=0; int j=strlen(s)-1; while(i { int temp=s[i]; s[i]=s[j];原创 2008-08-01 10:18:00 · 10829 阅读 · 0 评论 -
radix sort &&bucket sort
//桶式排序bucket sort//radix sort较小的数作为基数,采取多趟桶式排序的方法。具体做法是最低有效位优先,将各数放入痛中;然后调整,依次类推到最高有效位。#include#include#include#include#define BUKETSIZE 10typedef struct listitem{ int _value; struct listitem原创 2008-08-02 14:28:00 · 4466 阅读 · 1 评论 -
马尔可夫。。。。
不得不说,the practice of programming 一书真的很不错。。。。。根据一些文字的模式,随即生产文字。。。具体做啥找书看。。。。#include#include#includeenum{ NPREF = 2, //number of prefix words NHASH = 4093, //size of state hash原创 2008-09-22 20:53:00 · 4116 阅读 · 0 评论 -
libpcap 使用(1)
计算机网络自顶向下 一书中,介绍了ethereal。 该软件开源,用于抓包分析。版本最新的更名为wireshark,是目前最好的网络抓包分析工具。ethereal主要使用了gtk+ 和 libpcap来进行设计。gtk +提供用户界面,而libpcap是unix/linux平台下的网络数据包捕获函数包,大多数网络监控软件都以它为基础。Libpcap可以在绝大多数类unix平台下工作,提供了网原创 2008-10-23 19:53:00 · 5519 阅读 · 0 评论 -
lua + c语言 混合编程,灵活+效率
print(os.date())print("call c func in lua ------the sum is:",fun_c(1,2))function sum(x,y) return x+yend =====================================================================================// /原创 2013-03-23 22:50:40 · 1648 阅读 · 0 评论