c/c++ 语法规则/对象模型
RunBoying
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C++单例模型的例子
#include #include using namespace std;class CGlobalInstance{ private: CGlobalInstance(); virtual ~CGlobalInstance(); static CGlobalInstance* m_this; public: static C原创 2011-12-30 10:01:57 · 752 阅读 · 0 评论 -
6个变态的C语言Hello World程序
下面的六个程序片段主要完成这些事情:输出Hello, World 混乱C语言的源代码 下面的所有程序都可以在GCC下编译通过,只有最后一个需要动用C++的编译器g++才能编程通过。hello1.c1234567891011 #define _________ } #define转载 2012-02-09 14:22:16 · 776 阅读 · 0 评论 -
C语言的谜题
这几天,本站推出了几篇关于C语言的很多文章如下所示:语言的歧义 [酷壳链接] [优快云链接]谁说C语言很简单? [酷壳链接] [优快云链接]6个变态的C语言Hello World程序 [酷壳链接] [优快云链接]如何加密/弄乱C源代码 [酷壳链接] [优快云链接]C语言的谜题 [酷壳链接] [优快云链接]我们可以看到很多C语言相关的一些东西。比如《语言的歧转载 2012-02-09 14:13:40 · 630 阅读 · 0 评论 -
ACE 在linux环境下安装配置
转载自:http://blog.c114.net/html/87/367587-66548.html 本文是自己实践及网上资料搜集整理,放在这里作备忘。ACE 在linux环境下安装配置1. 下载ACE源文件:http://download.dre.vanderbilt.edu tar -xvzf [tar包名] 2. 设置环境变量$ vi .bash_profi转载 2012-01-04 10:11:35 · 845 阅读 · 0 评论 -
C 箴言:多态基类中将析构函数声明为虚拟
转自:http://www.west263.com/info/html/chengxusheji/C-C--/20080224/12883.html有很多方法能够跟踪时间的轨迹,所以有必要建立一个 TimeKeeper 基类,并为不同的计时方法建立派生类: class TimeKeeper { public: TimeKeeper(); ~TimeKee转载 2011-12-31 14:58:47 · 737 阅读 · 0 评论 -
c++基类不为虚析构函数的一个风险
#include using namespace std;class Point {public: //如果这里不写成虚拟的析构函数,子类就会有内存泄漏 //virtual ~point() //{ // cout<<"point out"<<endl; //} ~Point() { cout<<"point out"<<endl; }};clas原创 2011-12-31 14:57:42 · 759 阅读 · 0 评论 -
关于c++中构造函数的知识
#include using namespace std;class X{public: X(int b) { printf("test\n"); } ~X() { }};int main(){ X n; system("pause");}//vc2005编译报错//main.cpp(15) : error C2512: “X”: 没有合原创 2012-02-06 08:19:18 · 549 阅读 · 0 评论 -
Linux平台可以用gdb进行反汇编和调试。
转载自:http://www.cppblog.com/liu1061/articles/53762.html 如果在Linux平台可以用gdb进行反汇编和调试。(转)2. 最简C代码分析 为简化问题,来分析一下最简的c代码生成的汇编代码: # vi test1.c int main() { return 0;转载 2011-12-30 23:14:42 · 879 阅读 · 0 评论 -
Linux常用的网络命令
转载自:http://www.cnblogs.com/hnrainll/archive/2011/10/12/2208436.html网络参数设置命令 所有时刻如果你想要做好自己的网络参数设置,包括IP参数、路由参数和无线网络等,就得要了解下面这些相关的命令才行。其中Route及ip这两条命令是比较重要的。当然,比较早期的用法,我们都是使用ifconfig的。? ifconfig:转载 2011-12-30 22:33:28 · 1419 阅读 · 0 评论 -
c++ operator[]的例子
#include #include #include using namespace std;class X{public: int operator[](int key) { switch(key) { case 1: return 10; break; case 2: return 20; break; defa原创 2011-12-30 16:50:16 · 1163 阅读 · 0 评论 -
C++ map容器的2种初始化方法
#include #include #include using namespace std;int main(){ map map1; map1[string("tttt")] = 1; map1[string("ggg")] = 2; map1.insert(pair("niubi", 3)); map::iterator it = map1.begin();原创 2011-12-30 16:43:43 · 53379 阅读 · 2 评论 -
关于c++多重继承下的函数调用注意的问题
#include using namespace std;class A //commserver{public: virtual void g()=0; virtual void f() //f deal_all_msg //g deal_busseines_msg { printf("A\n"); g(); }};class B:public A //原创 2012-02-08 16:04:31 · 812 阅读 · 0 评论 -
c++多次delete的后果及正确处理方法
#include using namespace std;class X{public: int a;};int main(void){ X *x = new X; cout<<x<<endl; delete x; cout<<x<<endl; //多次delete 会爆异常 //delete x; system("pause"); return 0;}原创 2011-12-30 11:43:02 · 4491 阅读 · 1 评论 -
C++类静态变量使用注意的问题
#include using namespace std;class X{public: static int a; const static int c =10;private: static int b ;public: int get() { return b; }};//静态变量可以在外部定义和赋值,即便它是private的//int原创 2011-12-30 10:13:34 · 1642 阅读 · 0 评论 -
Oracle occi 绑定变量提高数据插入速度
转载自:http://fengqing888.blog.163.com/blog/static/3301141620111018017212/occi是oracle提供的一套对oci封装好的类库,前段时间我抽空看了看相关的文档,本来是想好好的研究研究的,不过因为一直有别的事情要做,所以就没有时间看下去了。论坛上用PRO*C的人多一些。用OCI的好像很少,而且一般问都问些简单的问题,描述的也转载 2012-01-21 09:44:06 · 4596 阅读 · 0 评论 -
绕过libsafe的保护--覆盖_dl_lookup_versioned_symbol技术
转载自:http://zjss.shayit.com/?news&t=7925&forum=24 在这里向您展现一下新的覆盖_dl_lookup_versioned_symbol技术 (这技术我提的,就这么命名好了:) ) 错误之处,还请来信斧正,谢谢。上接> 由于libsafe只保护堆栈区,不保护heap,和bss区,所以,我们可以设法覆盖那里的某些重要变量,从而使我转载 2012-01-12 08:27:39 · 2181 阅读 · 0 评论 -
带版本号的符号 versioned symbol
转载自:http://blog.chinaunix.net/space.php?uid=222028&do=blog&id=2658492 小小疏忽,折腾了我近一天的时间,不过总算弄清了个大概。碰到几次带版本的符号的连接问题,令人头疼。终于狠下心来,花了两天时间把info ld Scripts看了一遍,感觉大有长进。突然有股冲动,想译完ld script部分。转载 2012-01-12 08:25:57 · 4475 阅读 · 0 评论 -
GNU ld链接脚本学习
转载自:http://blog.chinaunix.net/space.php?uid=13701930&do=blog&id=336529 链接器脚本 *********** 每次一次链接行为都是被链接器脚本控制,这样的脚本是采用链接器命令语言写成. 这种脚本主要用途描述如何把输入文件中各段(section)组织到输出文件,并控制输出输出文件的内存布局.大部分链接转载 2012-01-12 08:26:42 · 3595 阅读 · 0 评论 -
关于c中防止头文件重复包含的2个方法
转载自百度 :http://baike.baidu.com/view/1276747.htm #pragma once #pragma once 这是一个比较常用的指令,只要在头文件的最开始加入这条指令就能够保证头文件被编译一次 #pragma once用来防止某个头文件被多次include,#ifndef,#define,#endif用来防止某个宏被多次定义。转载 2012-01-11 09:19:27 · 852 阅读 · 0 评论 -
C数据类型对齐规则包含位域
C数据类型对齐规则包含位域相关的操作:#pragma pack(n) 设置为n字节对齐#pragma pack(push) 保存当前的对齐字节数#pragma pack(pop) 还原默认对齐字节数vc默认8字节对齐1.对于结构体的各个成员,第一个成员位于偏移为0的位置2.对于结构体的以后的每个成员的开始偏移位置必须是MIN(#pragma pack()指定的数原创 2011-12-16 17:31:02 · 955 阅读 · 0 评论 -
linux2次锁互斥变量死锁的例子
linux2次锁互斥变量死锁的例子-------------------------------------------------- 1 #include 2 #include 3 #include 4 5 6 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 7 8 vo原创 2011-12-15 14:14:01 · 2011 阅读 · 1 评论 -
c c++内存操作
Cvoid * malloc ( size_t size );Allocate memory blockAllocates a block of size bytes of memory, returning a pointer to the beginning of the block.The content of the newly allocated block of原创 2011-12-23 15:45:44 · 760 阅读 · 0 评论 -
c++中的常量折叠 ,const与define是属于预编译的时候就被解析
转载:http://blog.youkuaiyun.com/yafeng_jiang/article/details/7101964先来看一个例子:[cpp] view plaincopy#include int main() { const int a=9; int *p=(int*)&a; *p=10; p转载 2012-02-13 20:51:42 · 1019 阅读 · 0 评论 -
c里面的数组尽量不要去做函数调用运算等操作
#include void gt(char**s){ (**s) ='b';}void ff(char* s){ *s = 1;} int main(){ char arr[3] = {0}; char* b = arr; gt(&b); //gt(arr) //语法错误 二级指针 ///gt(&arr) 这行会爆段错误 arr是一个数组名,原创 2012-02-13 21:27:23 · 933 阅读 · 0 评论 -
c++ 读写Oracle--Clob对象,注意数据编码长度
c++ 读写Clob对象,注意数据编码长度 读//p_rs 为resultset if (p_rs->next()) { Clob clob = p_rs->getClob(4); if (!clob.isNull()) {原创 2012-06-19 13:14:39 · 3670 阅读 · 0 评论 -
memset清空类的时候的3个不同效果
#includeusing namespace std;class A{ public: virtual void f() { printf("A.f called.\n"); } };class X:public A{原创 2012-06-14 08:45:00 · 1538 阅读 · 0 评论 -
memset引起的core问题
memset引起的core问题请看下面代码 memcpy((char*)t_added_content.m_cl_content, rs_resout->getString(2).c_str(), sizeof(t_added_content.m_cl_content) - 1);原来的想法是即便result原创 2012-05-23 15:58:41 · 2917 阅读 · 0 评论 -
c++,一个分号照成的严重bug
公司最近一次迭代测试中,打包出来的程序在验证问题单的时候发现没有提交消息到短信中心。查看模块日志发现在共享内存处理上面有问题,导致N多业务不能完成。经过跟踪到了一个cpp文件的某行。但是发现调用一个检查邮箱的函数就return false了很是奇怪。经过挂gdb调试也发现函数返回的是正确的值。而为什么一出来就是错误的。当时就在想是不是栈指针错误了,乱了。难道是偏移差一点的原因。在思考的原创 2012-06-12 12:44:20 · 1387 阅读 · 0 评论 -
类构造函数失败,如何返回NULL
#include #include #include using namespace std;class Myclass{public: Myclass(); void* operator new(size_t, char*); void operator delete(void*); int b_4;};//size表示new后面的对象大小 args是表示参数v原创 2012-03-22 13:49:26 · 3036 阅读 · 0 评论 -
加快make速度的2个方案预编译头与ccache的比较
Precompiled headers是将头文件编译成一个单独的文件,如果其他地方要以用这个头文件就会快很多方法是:用gcc 直接编译头文件Ccache有2种模式,direct mode与preprocessor mode。direct mode缓存所有编译过的头文件及源文件。如果下次编译的时候,代码没改过,就直接用!preprocess原创 2012-02-21 12:10:29 · 1522 阅读 · 0 评论 -
关于C中函数参数,指针-常量-引用解释的4个函数例子
#include #include void a( int* & k){ k = (int*)10; *k = 10;}void a(const int* & k){ k = (int*)10; //error不能给常量赋值 //*k = 10;}void f( int* & const b){ //引用后面的常量被忽略 b = (int*)10;}原创 2012-02-21 10:51:30 · 1274 阅读 · 0 评论 -
循环使用strrchr要注意的问题
直接上菜#include using namespace std;#include #include #include #define RC_FAILURE -1#define RC_SUCCESS 0int main(){ char a[] = "/home/g/f"; char *l =NULL; char *r =NULL; l =strrchr(a, '/'原创 2012-02-17 11:24:44 · 721 阅读 · 0 评论 -
c++类型转换
c++类型转换隐式类型转换 :概念:编译器完成的转换,不需要程序员手动转换。1 混合类型的算术表达式中,最宽的数据类型为目标转换类型2 将一种数据类型赋值给另外一种数据类型,被赋值对象的类型是目标转换类型3 把一个表达式传递给一个函数调用,表达式的类型与参数不同,形参的类型是目标转换类型4 从一个函数返回一个表达式,表达式与返回类型不同,函数返回类型是目标转换类型5 二元操作符算术原创 2012-02-24 16:42:01 · 1281 阅读 · 0 评论 -
获得linux线程栈的大小
获得linux线程栈的大小结果是:10485760 B 换算下 恰哈是10MB编译命令 gcc -lpthread p_stack.c代码:#include #include #include #include void* thread(){ pthread_attr_t pattr; size_t size = 0; printf("default s原创 2011-12-23 15:49:08 · 4846 阅读 · 1 评论 -
linux shell中,unlink和rm命令有什么区别
strace 跑 rm 與 unlink,結果有不同地方.1. strace rm 1.txt 片段access("1.txt", W_OK) = 0unlinkat(AT_FDCWD, "1.txt", 0) = 02. strace unlink 2.txt 片段unlink("2.txt")转载 2012-02-14 12:42:25 · 8399 阅读 · 1 评论 -
宏名字不规范,与结构体的成员重名
报错提示: 定义了宏名字不规范,与结构体的成员重名,导致了编译的时候提示结构体的这个类型不识别,很久才排除了这个错误!那么可以通过看预编译的源代码来分析是否被宏进行了替换 转载自:http://hi.baidu.com/hp_roc/blog/item/91691146c40de946500ffe39.html下面转载关于gcc的编译过程及文件的生成GCC编程四个过程:转载 2012-02-14 12:32:03 · 1680 阅读 · 0 评论 -
关于C数据类型长度
#include #include int main(){ printf("%d\n", sizeof(int)); printf("%d\n", sizeof(long)); printf("%d\n", sizeof(long int)); printf("%d\n", sizeof(long long)); printf("%d\n", sizeof(long doub原创 2012-02-21 09:58:47 · 739 阅读 · 0 评论 -
strdup,兼具malloc和strcpy的作用
原型:extern char *strdup(char *s); 头文件:#include 用法:char *strdup(char *s); 功能:复制字符串s 说明:strdup()在内部调用了malloc()为变量分配内存,当程序结束后,必须用free()释放相应的内存空间,否则会造成内存泄漏 举例: // strdup.c #include转载 2012-02-13 21:11:11 · 2401 阅读 · 0 评论 -
关于标准c中的strtok和linux库里面的strsep
转载自:http://snprintf.blog.51cto.com/3676303/695760strsep函数原型: Char * strsep(char **s1, const char *delimt); 需要注意:1、 被分割字串要被改变,所以不能操作存放在静态存储区的字串常量。2、 分割符要被替换成’\0’。3转载 2012-02-13 21:07:53 · 2188 阅读 · 0 评论 -
关于C++ dynamic_cast转换需要引起重视的问题
#include using namespace std;class CBase {public: virtual int b(){ return 0; }};class CDerived: public CBase { int b(){ return 0; }};int main(void){ //知识点1 //子类转基类没问题,因为空间变原创 2012-01-06 10:28:04 · 798 阅读 · 0 评论
分享