
C / C++ / JAVA 语言
stevenliyong
关注
C/C /JAVA
UML/RUP.
Linux.
Android.
Network/Bluetooth/WiFi.
展开
-
What is "Buffer Overflows" and "format string vulnerabilities"
伦敦大学孟博士极力推荐的内容. 网站是 http://doc.bughunter.net/ 1. C 语言缓冲溢出漏洞http://doc.bughunter.net/buffer-overflow/buffer-overflows.html 2. C++ 虚函数缓冲溢出漏洞http://doc.bughunter.net/buffer-overflow/cpp-原创 2008-12-30 09:16:00 · 1139 阅读 · 0 评论 -
关于虚继承
在过去的学习中,我们始终接触的单个类的继承,但是在现实生活中,一些新事物往往会拥有两个或者两个以上事物的属性,为了解决这个问题,C++引入了多重继承的概念,C++允许为一个派生类指定多个基类,这样的继承结构被称做多重继承。 举个例子,交通工具类可以派生出汽车和船两个子类,但拥有汽车和船共同特性水陆两用汽车就必须继承来自汽车类与船类的共同属性。 由此我们不难想出如下的图例转载 2008-12-18 16:16:00 · 992 阅读 · 0 评论 -
JAVA 中 getMethod()和invoke()方法应用
转自:http://www.blogjava.net/vesung/archive/2008/01/24/177447.html 一个简单的需求的实现:在程序中调用某类的某方法,并将返回结果println() 出来。实现方法:MethodTest.javaimport java.util.ArrayList;import java.util.List;import java.lang.转载 2009-08-30 13:24:00 · 23326 阅读 · 3 评论 -
final finally finalize 的区别
final 用于声明属性,方法和类,分别表示属性不可变,方法不可覆盖,类不可继承。finally是异常处理语句结构的一部分,表示总是执行。finalize是Object类的一个方法,在垃圾收集器执行的时候会调用被回收对象的此方法,可以覆盖此方法提供垃圾收集时的其他资源回收,例如关闭文件等转载 2009-09-01 17:09:00 · 568 阅读 · 0 评论 -
TinyXML:一个优秀的C++ XML解析器
转自 http://www.cnblogs.com/phinecos/archive/2008/03/11/1100912.html 读取和设置xml配置文件是最常用的操作,试用了几个C++的XML解析器,个人感觉TinyXML是使用起来最舒服的,因为它的API接口和Java的十分类似,面向对象性很好。TinyXML是一个开源的解析XML的解析库,能够用于C++,能够在Windows或转载 2009-10-22 09:39:00 · 863 阅读 · 0 评论 -
sscanf function reference (using of %*)
1. 函数定义 int sscanf ( const char * str, const char * format, ...);有一种用法:char* reply = "String Ingnored 10";int number;sscanf(replay,"%*s %*s %d", &number); 代码中的 %*s 表明忽略一个字符串, 其中*的定义如下原创 2010-03-04 10:37:00 · 775 阅读 · 0 评论 -
一道C++题目
<br />来自Cai-san 出的一道公司的面试题目, 以后向Cai-san 学习的机会比较少了, 可惜啊<br /> <br />在运行时,我们可以用<br />#define PAD_SIZE(s) (((s)+3)&~3)<br />PAD_SIZE(sizeof(T)) == sizeof(T)<br />判断一个数据类型是否没有被编译器填充数据。<br />那么编译时如何做?<br /><br /><br /><br />答案是<br /><br />// -------原创 2010-07-08 18:02:00 · 1118 阅读 · 0 评论 -
C Programming FAQs: Frequently Asked Questions
By Steve Summit http://c-faq.com/原创 2010-05-19 11:19:00 · 852 阅读 · 0 评论 -
Escape Problem
题目描述Hamilton, the famous thief, plans a bank robbery in L.A. When searching for the escape route, he takes two main factors into consideration. First, he cannot pass through any intersection twice原创 2010-05-20 16:24:00 · 993 阅读 · 0 评论 -
求一个Byte 的字节数据中, 二进制数1的个数
查表法int countTable[256] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };int Count(int v) { return countTable[v & 0x0F] + countTable[v >> 4]; }原创 2010-06-02 15:58:00 · 1179 阅读 · 0 评论 -
Swapping variables.
http://www.azillionmonkeys.com/qed/case3.html#define swap(a,b) { / (a) ^= (b); / (b) ^= (a); / (a) ^= (b); / }#define swap(a,b) { / (a) += (b); / (b) = (a) - (b); / (a) -= (b); / }转载 2010-06-03 10:48:00 · 568 阅读 · 0 评论 -
big endian and little endian
<br />unsignedchar test_bigendian(void) <br />{ <br /> int test_var =1; <br /> unsignedchar test_endian*=(unsignedchar*)&test_var; <br /> <br /> return(test_endian[0]== NULL); <br />} <br /><br />int little_endian_to_big_endian(int i)<br />{<br />原创 2010-06-02 15:54:00 · 595 阅读 · 0 评论 -
How can I determine the byte offset of a field within a structure?
#define offsetof(type, f) ((size_t) / ((char *)&((type *)0)->f - (char *)(type *)0))转载 2010-06-03 11:09:00 · 655 阅读 · 0 评论 -
Low Level Operators and Bit Fields
<br /> From Dave Marshall<br />1/5/1999<br />http://www.cs.cf.ac.uk/Dave/C/node13.html#SECTION001321000000000000000<br /> Low Level Operators and Bit Fields<br /> We have seen how pointers give us control over low level memory operations.<br />Many转载 2010-06-03 13:31:00 · 633 阅读 · 0 评论 -
UnrepeatingNunbers
Problem Statement:<br /> 如果一个数字十进制表达时,不存在连续两位数字相等,则称之为“不重复数”。例如,105,1234和12121都是“不重复数”,而11,100和1225不算。给定一个long类型数字A,返回大于A的最小“不重复数”。 Definition:<br />Class: UnrepeatingNumbers <br />Method: next <br />Parameters: long <br />Returns: long原创 2010-06-01 14:52:00 · 487 阅读 · 0 评论 -
判断一个数是否为2的幂?
<br />http://www.cppblog.com/converse/archive/2006/07/10/9664.html<br /> <br /><br /><br />bool Is2Power(int nNum)<br />{<br /> return nNum > 0 ? ((nNum & (~nNum + 1)) == nNum ? true : false) : false;<br />}<br /><br />或者<br /><br />#define IS_POWER_OF原创 2010-06-02 16:17:00 · 561 阅读 · 0 评论 -
vCard解析 可以用libmimedir 了
以前项目 vCard 解析部分的代码是自己写的,时不时有问题出来. 现在可以用libmimedir替代了. libmimedir 依赖于 glib,不过两者都是LGPL协议的,我们可以放心使用. 前面编译BlueZ中也用到了glib. 所以现在交叉编译libmimedir就很简单了. export PKG_CONFIG_LIBDIR=/usr/arm-xscale原创 2008-12-19 13:08:00 · 2510 阅读 · 0 评论 -
C++函数对象(转)
标准库里的count_if可以统计容器中满足特定条件的元素的个数。例如要统计一个整数vector——ivec中正数的个数,可以先写一个返回类型为bool,含有一个int参数的条件函数:bool pred(int val){ return val>0;}之后可以用count_if(ivec.begin(),ivec.end(),pred)计算出正整数的个数。但这个方法有一个转载 2009-03-02 18:29:00 · 679 阅读 · 1 评论 -
Command Pattern: We used but we didn't recognize (转)
Command Pattern: We used but we didnt recognize Class A wanna class B do what he want to (command). Simple way, invoke Bs method, thats a good idea, but dont follow the OO principle转载 2009-03-02 17:33:00 · 590 阅读 · 0 评论 -
Effective C++ 摘录
Item 1: 将 C++ 视为 federation of languages(语言联合体)最简单的方法是不要将 C++ 视为一个单一的语言,而是一个亲族的语言的 federation(联合体)。在每一个特定的 sublanguage(子语言)中,它的特性趋向于直截了当,简单易记。但你从一个 sublanguage(子语言)转到另外一个,它的规则也许会发生变化。为了感受 C++,你必须将它的主原创 2009-01-05 17:12:00 · 705 阅读 · 0 评论 -
public继承后,父类与子类访问隐藏
转自http://www.cppblog.com/iuranus/archive/2009/01/05/71210.html 《Effective C++》的第六章节继承与面向对象设计花了大部分的篇幅在介绍继承遮掩(Hiding Inherited Name),那我也效仿下大师,做个小的总结。 public继承的目的是要建立父子类的is-a关系,也就是说用到父类的地方,在子转载 2009-01-05 11:21:00 · 1366 阅读 · 0 评论 -
关于 C++ 左操作数和右操作数
1.a * b与函数调用operator*(a,b)是等价的。 2.const Rational operator*(const Rational& lhs, const Rational& rhs);你可以看到,left-hand operand(左手操作数)a 在函数内部以 lhs 的面目出现,而 right-hand operand(右手操作数)b 以原创 2009-01-05 17:09:00 · 6811 阅读 · 0 评论 -
C++ 库
C++ 没有 threads(线程)的概念——实际上,是没有任何一种 concurrency(并发)的概念。对于 C++ 标准库也是同样如此。就 C++ 涉及的范围而言,multithreaded programs(多线程编程)并不存在。 TR1 和 BoostTR1 ("Technical Report 1") 是被加入 C++ 标准库的新机能的 specification(原创 2009-01-05 17:11:00 · 696 阅读 · 0 评论 -
C++ 隐式和显式 初始化,类型转换
1. 隐式和显式初始化1.1 C++隐式初始化int ival(1024);string hello("Hello world.")1.2 C++显式初始化int ival = 1024;string hello = "Hello world." *PS: 注意这里"=" 语法是拷贝构造函数而不是赋值运算! 因为一个新对象被定义一定要有一个构造函数而不不是一个赋值操作原创 2009-01-05 14:02:00 · 4239 阅读 · 5 评论 -
C++ 接口和对象分离的技术
C++ 接口和对象分离的技术这是Effective C++ Item 31的内容.先看一下这个类class Person {public: Person(const std::string& name, const Date& birthday, const Address& addr); std::string name() const; std::strin原创 2009-01-07 12:53:00 · 924 阅读 · 0 评论 -
关于结构体数据对齐(About data alignment)
1. 编译器通常会使结构体强制对齐. 这里默认使用VC编译器,默认8bytes 对齐的,对于结构体struct struct_x { char a; // 1 byte int b; // 4 bytes short c; // 2 bytes char d; // 1 byte} ; 编译器会自动插入一些pad原创 2009-01-07 13:36:00 · 3000 阅读 · 2 评论 -
C++ 通过成员函数参数返回成员数组的值
C++ 通过成员函数参数返回成员数组的值通常对数组类型进行保护做法是这样的。 class A {public : A {} ~ A {} enum { MAX_VAL_COUNT = 10;}; void getArraryValues(int (* pVal)[MAX_VAL_COUNT]) { memcpy(pVal,m_aVal,原创 2009-01-09 17:56:00 · 1686 阅读 · 0 评论 -
C++使用对象来管理动态分配资源
C++使用对象来管理动态分配资源1. 引入void f(){ Investment *pInv = createInvestment(); // call factory function ... // use pInv delete pInv;原创 2009-01-07 17:17:00 · 1498 阅读 · 2 评论 -
C++ RTTI(Run-Time Type Indentifiation,运行时刻类型识别)
C++ RTTI(Run-Time Type Indentifiation,运行时刻类型识别)RTTI 运行时刻类型识别允许用指向基类的指针或引用来操纵对象的程序能够获取到这些指针或引用所指对象的实际派生类型在c++中为了支持RTTI 提供了两个操作符dynamic_cast和typeid1 dynamic_cast 操作符可以用来把一个类类型对象的指针转换成同一类层次结构中的其他类的指针原创 2009-01-08 14:04:00 · 1018 阅读 · 0 评论 -
应用auto_ptr, singleton的实现
实现方式:#ifndef Singleton_H#define Singleton_Htemplate class Singleton{public: static inline T* getInstance();private: Singleton(void){} virtual ~Singleton(void){} Singleton(const Singl原创 2009-02-19 09:28:00 · 1286 阅读 · 0 评论 -
C++ Object Size
#include class A1{};class A2{public: virtual ~A2() {};};class B1 : public A1{};class B2 : public A1{private: char c;};class B3 : public A1{private原创 2009-02-24 10:37:00 · 1025 阅读 · 0 评论 -
关于 const char* p , char const* p 以及 char * const p
1. 首先, const char c 和 char const c 是等价的.const 修饰的是变量c(前者只不过将const 修师符提到了最前面), 变量c 是char 类型的. 2.再来看const修饰指针的情况.const char* p : 因为const 修饰符在 * 号前面,因此const 修饰的是 (*p),因此p指向的字符串是const的.char原创 2009-02-25 09:28:00 · 3968 阅读 · 0 评论 -
include stdio.h 还是 cstdio
cstdio是c++从C的stdio.h继承来的,两者内容都一样,只不过cstdio头文件中定义的名字被定义在命名空间std中。在C++中要尽量避免C风格的出现, 因此需要使用 #include .原创 2009-02-25 10:48:00 · 3593 阅读 · 2 评论 -
一个C++异常的问题
#include #include void f0(){ throw "0";}void f1() throw(){ throw "1";}void f2() throw(int){ throw "2";}void f3() throw(char*){ throw "3";}int原创 2009-02-26 15:15:00 · 767 阅读 · 0 评论 -
Size of an array
<br />Q:I want to know how many elements are in an array,but sizeof yields the size in bytes.<br />A:Simply divide the size of the entire array by the size of one element: int array[] = {1, 2, 3};<br /> int narray = sizeof(array) / sizeof(arr转载 2010-06-03 16:53:00 · 584 阅读 · 0 评论