
c++
文章平均质量分 66
fatshaw
这个作者很懒,什么都没留下…
展开
-
some special cases of "extern" in C
we can use extern to specify that a symbol is defined somewhere else, e.ga.c:extern int a;b.cint a;When compiling a.c compiler knows that a原创 2011-07-22 11:20:48 · 683 阅读 · 0 评论 -
C字符串处理函数
void *memccpy (void *dest, const void *src, int c, size_t n);从src所指向的对象复制n个字符到dest所指向的对象中。如果复制过程中遇到了字符c则停止复制,返回指针指向dest中字符c的下一个位置;否则返回NULL。void *memcpy (void *dest, const void *src, size_t n);转载 2009-02-04 10:45:00 · 731 阅读 · 0 评论 -
关于c++中new和delete的长度问题
在使用标准的g++时,new的时候在申请地址的前面会有个结构保存申请到的内存的长度,具体说明结合代码说明:#include using namespace std;class Test{private: int a;public: Test(){}原创 2010-11-03 15:33:00 · 2735 阅读 · 2 评论 -
在VS2008中编译纯c/c++程序并由c#调用过程
1. 建立一个C#控制台工程,主要用于调试。2. 在解决方案中添加一个新的空工程(VC++的)。3. 添加一个源文件到Source Files文件夹(xxx.c or xxx.cpp)。4. 加入这行代码#include extern "C" __declsp转载 2010-07-10 10:49:00 · 1313 阅读 · 0 评论 -
网络字节顺序、大端法、小端法
在网络传输时,将long类型先转化为byte数组,步骤如下:long l;byte[] b;b[0]=(byte)(l>>>24);b[1]]=(byte)(l>>>16);b[2]]=(byte)(l>>>8);b[3]]=(byte)(l);此转载 2010-06-23 19:45:00 · 9727 阅读 · 0 评论 -
封装不同类的不同名称的方法
if we have two classes, Apple and Orange. Apple has a method named print, while Orange has a method named write. we want to use a uniform interface to realize the output function. in the article , i原创 2010-05-08 18:02:00 · 573 阅读 · 0 评论 -
using dynamic library in c++
when we use c++ , we always need write many library code so that we can use it in many places. in the article, i will introduce how to write and use dynamic library in windows and linux. 1 . Fir原创 2010-04-24 22:08:00 · 868 阅读 · 0 评论 -
一些c语言字符串处理
很多人认为C语言中的难点是指针,对指针的理解直接关系到所编程序的好坏,所以,在这里列举了一些C编译器通常都有的标准函数的源代码,看过它们,就能对指针和字符串有所了解了.1. strlen(),计算字符串长度int strlen(const char string){int i=0;while(string[i]) i++;return i;}2. str转载 2010-03-24 22:26:00 · 1135 阅读 · 0 评论 -
判断CPU的大小端
首先介绍下大小端的概念。对于一个数0x1122使用Little Endian方式时,低字节存储0x22,高字节存储0x11而使用Big Endian方式时, 低字节存储0x11, 高字节存储0x22大多数os都是用的小端。有些专用系统用的大端。 方法一:bool IsBigendian() { unsigned short usData = 0x1122原创 2010-03-22 09:46:00 · 1396 阅读 · 0 评论 -
判断一个数是不是2的幂次
判断一个数是2的n次幂的方法 : 2的n次幂的形式是10,100,1000,10000,……,所以!(x & (x-1))为真即x为2的幂次。 观察4个幂次的二进制可以发现,形式为100,10000,1000000,……,这个和上面的2的幂次一样,(x & (x -1) ) 一定是0,但是这还不够的,因为4的幂次后面的0是偶数个的,如果以4位一格看的话,即1的位置是在第1位和第原创 2010-01-17 14:22:00 · 1013 阅读 · 0 评论 -
不排序和可以重复Key的SortedList
在写dbscan的时候用到了sortedlist,但是sortedlist不支持相同键的存储,可以使用以下办法。using System;using System.Collections;namespace testSortedList{ class Class1 { [STAThread] static void M转载 2010-01-12 18:23:00 · 1464 阅读 · 0 评论 -
C语言里面字符串操作是关于格式的参数
specifierOutputExamplecCharacterad or iSigned decimal integer392eScientific notation (mantise/exponent) using e character3.9265e+2EScientific notat原创 2009-02-04 10:46:00 · 643 阅读 · 0 评论 -
main 之前与之后
我之所以提出这个问题,缘于一些IT公司招聘开发人员的笔试题或者面试题:C++ 中能不能让一些代码在 main() 之前或者之后执行?答案理所当然可以的。这可以有很多实现方法。下面例举:1、一般来说,全局域的变量(包括静态变量)赋值、初始化等工作都是在main之前执行的转载 2011-08-23 15:07:08 · 1671 阅读 · 0 评论 -
c++笔试面试总结
C++:1. c++的new可以指定地址struct T:B{ public: void * operator new(size_t sz, T& t){}};int main(){ T tb; T * t = new(tb) T; //必须是tb在前,因为tb指明size,不知道这个有什么用}2. c+原创 2011-11-28 20:47:40 · 1755 阅读 · 0 评论 -
回调函数
简介 对于很多初学者来说,往往觉得回调函数很神秘,很想知道回调函数的工作原理。本文将要解释什么是回调函数、它们有什么好处、为什么要使用它们等等问题,在开始之前,假设你已经熟知了函数指针。 什么是回调函数? 简而言之,回调函数就是一个通过函数指针调用的函数。如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调转载 2009-02-05 10:44:00 · 523 阅读 · 0 评论 -
wchar_t与char转换
C++标准中,wchar_t是宽字符类型,每个wchar_t类型占2个字节,16位宽。汉字的表示就要用到wchar_t 。char,我们都知道,占一个字节,8位宽。其实知道了这个以后,要在wchar_t 和 char两种类型之间转换就不难实现了。wchar_t 转换为char 的代码如下: 有如下的wchar_t和char变量:wchar_t w_cn = 中; char c_转载 2009-02-11 16:28:00 · 1165 阅读 · 0 评论 -
函数指针
函数存放在内存的代码区域内,它们同样有地址,我们如何能获得函数的地址呢? 如果我们有一个int test(int a)的函数,那么,它的地址就是函数的名字,这一点如同数组一样,数组的名字就是数组的起始地址。 定义一个指向函数的指针用如下的形式,以上面的test()为例: int (*fp)(int a);//这里就定义了一个指向函数的指针 函数指针不能绝对不能指向不同类型,或者原创 2009-02-17 11:54:00 · 491 阅读 · 0 评论 -
C/C++预处理指令#pragma详解
<br /> 在所有的预处理指令中,#Pragma指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作。#pragma指令对每个编译器给出了一个方法,在保持与C和C ++语言完全兼容的情况下,给出主机或操作系统专有的特征。依据定义,编译指示是机转载 2011-06-02 14:19:00 · 972 阅读 · 0 评论 -
stack changes when calling function in c
C code:int f(int a, int b){ a=1; int variable1=2; int variable2=1; return 0;}int main(){ f(1,2);原创 2011-04-30 23:53:00 · 1090 阅读 · 0 评论 -
strong reference and weak reference
Cyclic ReferencesReferencecounting is a convenient resource management mechanism, it has one fundamental drawback though: cyclic reference转载 2011-04-12 22:11:00 · 1077 阅读 · 0 评论 -
Design Principles
Design PrinciplesWhat are Software Design Principles?Software design principles represent a set of guidelines that helps us to avoid havi转载 2011-04-14 14:20:00 · 718 阅读 · 0 评论 -
simple ref count in C/C++
<br />ref count is a very useful tech in managing resource in c/c++<br /> <br />simply in c we can use the following code to implement ref c原创 2011-02-16 11:06:00 · 884 阅读 · 0 评论 -
c/c++ 内存泄露检测
<br />在做c/c++程序时关键的问题是如何进行内存管理,如果内存操作不当可能造成内存泄露。我个人认为内存泄露的根本原因在于申请了一个内存但是没有释放,随着程序的不断运行,进程占用的内存不断增长,造成内存泄露<br /> <br />在平时工作中我使用一个比较简单但是有效的方原创 2011-01-26 18:04:00 · 1022 阅读 · 0 评论 -
Python/C interface
Write a c program to interface with python script. Python is written in c and it provides c api to let programmers to call python module in原创 2011-01-19 16:25:00 · 1567 阅读 · 0 评论 -
java concurrent synchronization
<br />synchronized keyword usage in java<br /><br />We can add keyword "synchronized" at the beginning of function to lock the function whe原创 2011-01-17 15:33:00 · 620 阅读 · 0 评论 -
c++ 多重继承中的动态绑定
c++中可以使用多重继承,即一个子类可以继承多个父类。多重继承存在很多问题,如二义性问题。对于动态绑定是不是也有二义性问题。 代码1:#include using namespace std;class Base1{ public:原创 2010-11-21 19:37:00 · 1302 阅读 · 0 评论 -
extern "C"的用法
去sony笔试,问了个extern “C”的题目,我以前一直认为c要调用c++的函数需要把c++的函数使用extern “C”申明下,告诉c++编译器我的c++代码用c的规范去编译,好让c的编译器能够调用。但是现在发觉c++调用c的代码时也需要将c的函数用extern “C”申明原创 2010-11-20 15:40:00 · 1239 阅读 · 0 评论 -
C# string to byte[]
C#中将string转为byte[]System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();Byte[] bytes = encoding.GetBytes(yourString);转载 2010-06-26 18:00:00 · 8678 阅读 · 0 评论 -
C++静态成员小结
静态类成员包括静态数据成员和静态函数成员两部分。 一 静态数据成员: 类体中的数据成员的声明前加上static关键字,该数据成员就成为了该类的静态数据成员。和其他数据成员一样,静态数据成员也遵守public/protected/private访问规则。同时,静态数据成员还具有以下特点:1.静态数据成员的定义。 静态数据成员实际上是类域中的全局变量。所以,静态数据转载 2010-05-28 16:34:00 · 520 阅读 · 0 评论 -
set使用自定义元素方法
struct p{ int w p(int w):w(w){}}struct cmp{ bool operator()(cosnt p & p1, const p & p2)//parameter must be const,or it will be compile error { return p1.w > p2.w;//reverse sort原创 2010-05-10 12:07:00 · 883 阅读 · 0 评论 -
12 Interesting C Interview Questions and Answers
Transfer from a programmer web site. quite interesting but basic C interview questions. In this article, we will discuss some interesting problems on C language that can help students to brush up转载 2012-09-09 22:44:38 · 1118 阅读 · 0 评论