??xml version="1.0" encoding="utf-8" standalone="yes"?>国产日韩欧美一区在线,伊人婷婷久久,中文字幕一区avhttp://www.aygfsteel.com/sunxiaobo/category/35092.htmlEclipse-Unix http://umlfact.berlios.de/~s_xsun/zh-cnWed, 19 Aug 2009 20:16:59 GMTWed, 19 Aug 2009 20:16:59 GMT60void* (like Object in Java)http://www.aygfsteel.com/sunxiaobo/archive/2009/02/05/253448.htmlXiaobo SunXiaobo SunThu, 05 Feb 2009 13:07:00 GMThttp://www.aygfsteel.com/sunxiaobo/archive/2009/02/05/253448.htmlhttp://www.aygfsteel.com/sunxiaobo/comments/253448.htmlhttp://www.aygfsteel.com/sunxiaobo/archive/2009/02/05/253448.html#Feedback0http://www.aygfsteel.com/sunxiaobo/comments/commentRss/253448.htmlhttp://www.aygfsteel.com/sunxiaobo/services/trackbacks/253448.html   Ҏ性,它可以存攑օ他Q何类型的指针cdQ例如:  
                                        char   *array="I   am   the   pointer   of   string";  
                                        void   *   tempQ?                  //temp可以存放其他Mcd的指?地址Q? 
                                        temp=array;                       //   temp   的指针类? 
                                        cout<<array<<endl;  
                                        cout<<temp<<endl;  
                                        cout<<(char   *)temp<<endl;  
  q行l果Q? 
                                      I   am   the   pointer   of   string  
                                      0x0042510C   Q这个值就是array指针变量所存储的|  
                                      I   am   the   pointer   of   string  
   
   
   
  2.但是不能void*cd的Dl其他既定的cdQ除非经q显C{换:   例如Q? 
                                                                    int   a=20;  
                                                                    int   *   pr=&a;  
                                                                      void   *p;  
                                                                      pr=p               //error,不能空的类型赋lint   *  
 
                                                                      pr=(int   *)p;     //okQ经q{?nbsp;

Xiaobo Sun 2009-02-05 21:07 发表评论
]]>
externhttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/30/237689.htmlXiaobo SunXiaobo SunThu, 30 Oct 2008 12:36:00 GMThttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/30/237689.htmlhttp://www.aygfsteel.com/sunxiaobo/comments/237689.htmlhttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/30/237689.html#Feedback0http://www.aygfsteel.com/sunxiaobo/comments/commentRss/237689.htmlhttp://www.aygfsteel.com/sunxiaobo/services/trackbacks/237689.html1 基本解释

extern可以|于变量或者函数前Q以标示变量或者函数的定义在别的文件中Q提C编译器遇到此变量和函数时在其他模块中寻扑օ定义?br />
另外Qextern也可用来q行链接指定?br /> 2 问题Qextern 变量

在一个源文g里定义了一个数l:

char a[6];

在另外一个文仉用下列语句进行了声明Q?br />
extern char *aQ?/td>

请问Q这样可以吗Q?

{案与分析:

1)、不可以Q?a class="bluekey" target="_blank">E序q行时会告诉你非法访问。原因在于,指向cdT的指针ƈ不等价于cdT的数l。extern char *a声明的是一个指针变量而不是字W数l,因此与实际的定义不同Q从而造成q行旉法访问。应该将声明改ؓextern char a[ ]?br />
2)、例子分析如下,如果a[] = "abcd",则外部变量a=0x61626364 (abcd的ASCII码?Q?a昄没有意义Q如下图Q?br />

昄a指向的空_0x61626364Q没有意义,易出现非法内存访问?br />
3)、这提示我们Q在使用extern时候要严格对应声明时的格式Q在实际~程中,q样的错误屡见不鲜?br />
4)、extern用在变量声明中常常有q样一个作用,你在*.c文g中声明了一个全局的变量,q个全局的变量如果要被引用,放?.h中ƈ用extern来声明?br />
3 问题Qextern 函数1

常常见extern攑֜函数的前面成为函数声明的一部分Q那么,C语言的关键字extern在函数的声明中v什么作用?

{案与分析:

如果函数的声明中带有关键字externQ仅仅是暗示q个函数可能在别的源文g里定义,没有其它作用。即下述两个函数声明没有明显的区别:

extern int f(); 和int f();

当然Q这L用处q是有的Q就是在E序中取代include “*.h”来声明函敎ͼ在一些复杂的目中,我比较习惯在所有的函数声明前添加extern修饰?br />
4 问题Qextern 函数2
 
当函数提供方单方面修改函数原型时Q如果用方不知情l沿用原来的externxQ这L译时~译器不会报错。但是在q行q程中,因ؓ了或者多了输入参敎ͼ往往会照成系l错误,q种情况应该如何解决Q?br />
{案与分析:

目前业界针对q种情况的处理没有一个很完美的方案,通常的做法是提供方在自己的xxx_pub.h中提供对外部接口的声明,然后调用方include该头文gQ从而省去externq一步。以避免q种错误?br />
宝剑有双锋,对extern的应用,不同的场合应该选择不同的做法?br /> ===============================================================================
4.extern "C"的惯用法

Q?Q在C++中引用C语言中的函数和变量,在包含C语言头文Ӟ假设为cExample.hQ时Q需q行下列处理Q?

extern "C"
{
#include "cExample.h"
}


而在C语言的头文g中,对其外部函数只能指定为externcdQC语言中不支持extern "C"声明Q在.c文g中包含了extern "C"时会出现~译语法错误?

W者编写的C++引用C函数例子工程中包含的三个文g的源代码如下Q?
C/C++ code


/* c语言头文ӞcExample.h */

#ifndef C_EXAMPLE_H

#define C_EXAMPLE_H

extern int add(int x,int y);

#endif

/* c语言实现文gQcExample.c */

#include
"cExample.h"

int add( int x, int y )

{

return x + y;

}

// c++实现文gQ调用addQcppFile.cpp

extern "C"

{

#include
"cExample.h"

}

int main(int argc, char* argv[])

{

add(
2,3);

return 0;

}





如果C
++调用一个C语言~写?DLLӞ当包?DLL的头文g或声明接口函数时Q应加extern "C" { }?br />


Q?/span>2Q在C中引用C++语言中的函数和变量时QC++的头文g需dextern "C"Q但是在C语言中不能直接引用声明了extern "C"的该头文Ӟ应该仅将C文g中将C++中定义的extern "C"函数声明为externcd?br />
W者编写的C引用C
++函数例子工程中包含的三个文g的源代码如下Q?br />


//C++头文?cppExample.h

#ifndef CPP_EXAMPLE_H

#define CPP_EXAMPLE_H

extern "C" int add( int x, int y );

#endif

//C++实现文g cppExample.cpp

#include "cppExample.h"

int add( int x, int y )

{

return x + y;

}

/* C实现文g cFile.c

/* q样会编译出错:#include "cExample.h"
*/

extern int add( int x, int y );

int main( int argc, char* argv[] )

{

add(
2, 3 );

return 0;

}







Xiaobo Sun 2008-10-30 20:36 发表评论
]]>
Ref as function paramhttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/23/236239.htmlXiaobo SunXiaobo SunThu, 23 Oct 2008 11:15:00 GMThttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/23/236239.htmlhttp://www.aygfsteel.com/sunxiaobo/comments/236239.htmlhttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/23/236239.html#Feedback0http://www.aygfsteel.com/sunxiaobo/comments/commentRss/236239.htmlhttp://www.aygfsteel.com/sunxiaobo/services/trackbacks/236239.html
常引用声明方式:const cd标识W?&引用?目标变量名;
用这U方式声明的引用Q不能通过引用对目标变量的D行修?从而引用的目标成?br /> constQ达C引用的安全性?br /> 【例3】:
int a ;
const int &ra=a;
ra=1; //错误
a=1; //正确
q不光是让代码更健壮Q也有些其它斚w的需要?br /> 【例4】:假设有如下函数声明:
string foo( );
void bar(string & s);
那么下面的表辑ּ是非法的:
bar(foo( ));
bar("hello world");
原因在于foo( )?hello world"串都会生一个时对象,而在C++中,q些临时对象都是
const cd的。因此上面的表达式就是试囑ְ一个const cd的对象{换ؓ非const cdQ?br /> q是非法的?br /> 引用型参数应该在能被定义为const 的情况下Q尽量定义ؓconst ?br />


Xiaobo Sun 2008-10-23 19:15 发表评论
]]>
pkg-config学习 http://www.aygfsteel.com/sunxiaobo/archive/2008/10/15/234504.htmlXiaobo SunXiaobo SunWed, 15 Oct 2008 11:12:00 GMThttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/15/234504.htmlhttp://www.aygfsteel.com/sunxiaobo/comments/234504.htmlhttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/15/234504.html#Feedback1http://www.aygfsteel.com/sunxiaobo/comments/commentRss/234504.htmlhttp://www.aygfsteel.com/sunxiaobo/services/trackbacks/234504.html
 首先说下/etc/ld.so.conf:

q个文g记录了编译时使用的动态链接库的\径?br /> 默认情况下,~译器只会?lib?usr/libq两个目录下的库文g
如果你安装了某些库,比如在安装gtk+-2.4.13时它会需要glib-2.0 >= 2.4.0,辛苦的安装好glib?br /> 没有指定 —prefix=/usr q样glib库就装到?usr/local下,而又没有?etc/ld.so.conf中添?usr/local/libq个搜烦路径Q所以编译gtk+-2.4.13׃出错?对于q种情况有两U方法解冻I
一Q在~译glib-2.4.xӞ指定安装?usr下,q样库文件就会放?usr/lib中,gtk׃会找不到需要的库文件了 对于安装库文件来_q是个好办法Q这样也不用讄PKG_CONFIG_PATH?br />
二:?usr/local/lib加入?etc/ld.so.conf中,q样安装gtk时就会去搜烦/usr/local/lib,同样可以扑ֈ需要的?br /> ?usr/local/lib加入?etc/ld.so.conf也是必须的,q样以后安装东东到local下,׃会出现这L问题了?br /> 自己可能存攑ֺ文g的\径都加入?etc/ld.so.conf中是明智的选择
dҎ也极其简单,库文g的绝对\径直接写q去OK了,一行一个。例如:
/usr/X11R6/lib
/usr/local/lib
/opt/lib

再来看看ldconfig Q?br />
它是一个程序,通常它位?sbin下,是root用户使用的。具体作用及用法可以man ldconfig查到
单的_它的作用是?etc/ld.so.conf列出的\径下的库文g ~存?etc/ld.so.cache 以供使用
因此当安装完一些库文gQ?例如刚安装好glib)Q或者修改ld.so.conf增加新的库\径后Q需要运行一?sbin/ldconfig
使所有的库文仉被缓存到ld.so.cache中,如果没做Q即使库文g明明在/usr/lib下的Q也是不会被使用的,l果~译q程中报错,~少xxx?br /> 我曾l编译KDE时就犯过q个错误Q?它需要每~译好一个东东,都要q行一?Q所以切记改动库文g后一定要q行一下ldconfigQ在M目录下运行都可以?br />
再来说说 PKG_CONFIG_PATHq个变量?

l常在论坛上看到有h?#8221;Z么我已经安装了glib-2.4.xQ但是编译gtk+-2.4.x q是提示glib版本太低阿?
Z么我安装了glib-2.4.xQ还是提C找不到阿?。。。。。?#8221;都是q个变量搞的鬹{?br /> 先说说它是哪冒出来的Q当安装了pkgconfig-x.x.xq个包后Q就多出了pkg-configQ它是需要PKG_CONFIG_PATH的东?br /> pkgconfig-x.x.x又是做什么的Q?来看一D说明:

The pkgconfig package contains tools for passing the include path and/or library paths to build tools during the make file execution.

pkg-config is a function that returns meta information for the specified library.

The default setting for PKG_CONFIG_PATH is /usr/lib/pkgconfig because of the prefix we use to install pkgconfig. You may add to PKG_CONFIG_PATH by exporting additional paths on your system where pkgconfig files are installed. Note that PKG_CONFIG_PATH is only needed when compiling packages, not during run-time.

其实pkg-config是向configureE序提供pȝ信息的程序,比如软g的版本啦Q库的版本啦Q库的\径啦Q等{?br /> q些信息只是在编译其间用。你可以 ls /usr/lib/pkgconfig 下,会看到许多的*.pc,用文本编辑器打开
会发现类g面的信息Q?br />
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums

Name: GLib
Description: C Utility Library
Version: 2.4.7
Libs: -L${libdir} -lglib-2.0
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include

明白了吧Qconfigure是靠这些信息判断你的Y件版本是否符合要求。ƈ且得到这些东东所在的位置Q要不去哪里扑֑?br /> 不用我说你也知道Z么会出现上面那些问题了吧?br />
解决的办法很单,讑֮正确的PKG_CONFIG_PATHQ假如将glib-2.x.x装到?usr/local/下,那么glib-2.0.pc׃?br /> /usr/local/lib/pkgconfig下,这个\径添加到PKG_CONFIG_PATH下就可以啦。ƈ且确保configure扑ֈ的是正确?br /> glib-2.0.pc,是其他的lib/pkgconfig目录glib-2.0.pcq掉是啦?如果有的?^-^)
讑֮好后可以加入到~/.bashrc中,例如Q?br /> PKG_CONFIG_PATH=/opt/kde-3.3.0/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/pkgconfig:
/usr/X11R6/lib/pkgconfig
[root@NEWLFS ~]#echo $PKG_CONFIG_PATH
/opt/kde-3.3.0/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/pkgconfig:/usr/X11R6/lib/pkgconfig

从上面可以看出,安装库文件时Q指定安装到/usrQ是很有好处的,无论?etc/ld.so.confq是PKG_CONFIG_PATH
默认都会L?usr/lib的,可以省下许多ȝQ不q从源码包管理上来说Q都装在/usr?br /> 理是个问题Q不如装?usr/local下方便管?br /> 其实只要讄好ld.so.confQPKG_CONFIG_PATH路径后,OK?

Xiaobo Sun 2008-10-15 19:12 发表评论
]]>
Makefile examplehttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/09/233437.htmlXiaobo SunXiaobo SunThu, 09 Oct 2008 12:55:00 GMThttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/09/233437.htmlhttp://www.aygfsteel.com/sunxiaobo/comments/233437.htmlhttp://www.aygfsteel.com/sunxiaobo/archive/2008/10/09/233437.html#Feedback3http://www.aygfsteel.com/sunxiaobo/comments/commentRss/233437.htmlhttp://www.aygfsteel.com/sunxiaobo/services/trackbacks/233437.html #macro
libxml2:=../../libxml2
libxml++:=..
glibmm:=../../glibmm
#adds include directives
CC:=g++
CCINCLUDE:= -I$(libxml++)/include/libxml++-2.6 -I$(libxml++)/lib/libxml++-2.6/include "
        -I$(libxml2)/include -I$(glibmm)/include
#linking
LD:=g++
LDSTDLIBS:= -L$(libxml++)/lib -L$(libxml2)/lib -L$(glibmm)/lib
LDLIBS:= -lxml++-2.6
LDLIBFLAGS:= -shared $(LDLIBS) $(LDSTDLIBS)
LDEXEFLAGS:= $(LDSTDLIBS) $(LDLIBS)
#extending library path
#export VAR:=... means make it effective in the subprocess(Makefile)
#export LD_LIBRARY_PATH:=... doesn't work because it's only effective in the subprocesses, not parentprocess(shell)
#therefore the LD_RUN_PATH which allocates dynamic libs to the exe file must be set and export to take effect in the ld cmd
LD_LIBRARY_PATH:=$(libxml++)/lib:$(LD_LIBRARY_PATH)
export LD_RUN_PATH:=$(LD_LIBRARY_PATH)
#list of source files for building the target
SRC:= main.cpp
OBJ:=$(patsubst %.cpp,%.o,$(filter %.cpp,$(SRC)))
#targets
# $^ everyone behinds the : , and $< first one behinds the :
# $(OBJ): %.o: %.cpp is another common implicit rule is for the construction of .o files out of .cpp
.PHONY: all clean
all: $(OBJ)
        $(LD) $(LDEXEFLAGS) $^ -o $@

$(OBJ): %.o: %.cpp
        $(CC) $(CCINCLUDE) -c $< -o $@
clean:
        rm -f $(OBJ) all *~ \.*.swp



Xiaobo Sun 2008-10-09 20:55 发表评论
]]>
gdbhttp://www.aygfsteel.com/sunxiaobo/archive/2008/08/05/220293.htmlXiaobo SunXiaobo SunTue, 05 Aug 2008 14:42:00 GMThttp://www.aygfsteel.com/sunxiaobo/archive/2008/08/05/220293.htmlhttp://www.aygfsteel.com/sunxiaobo/comments/220293.htmlhttp://www.aygfsteel.com/sunxiaobo/archive/2008/08/05/220293.html#Feedback0http://www.aygfsteel.com/sunxiaobo/comments/commentRss/220293.htmlhttp://www.aygfsteel.com/sunxiaobo/services/trackbacks/220293.html (gdb)set args -id 0 -taskcfg ub900proc
(gdb)r //run
Starting program: ../sysprocess -id 0 -taskcfg ub900proc
..
Program received signal SIGSEGV, Segmentation fault.
(gdb)backtrace //打印当前的函数调用栈的所有信息?br /> (gdb)frame 7 //查看信息Qn是一个从0开始的整数Q是栈中的层~号
(gdb)up
(gdb)down
(gdb)quit



Xiaobo Sun 2008-08-05 22:42 发表评论
]]>
LD_LIBRARY_PATHhttp://www.aygfsteel.com/sunxiaobo/archive/2008/06/16/208414.htmlXiaobo SunXiaobo SunMon, 16 Jun 2008 12:21:00 GMThttp://www.aygfsteel.com/sunxiaobo/archive/2008/06/16/208414.htmlhttp://www.aygfsteel.com/sunxiaobo/comments/208414.htmlhttp://www.aygfsteel.com/sunxiaobo/archive/2008/06/16/208414.html#Feedback0http://www.aygfsteel.com/sunxiaobo/comments/commentRss/208414.htmlhttp://www.aygfsteel.com/sunxiaobo/services/trackbacks/208414.html ====================
LD_LIBRARY_PATH: defines the path of dynamic libraries used at the run time
LD_RUN_PATH: at compile time tells the exe file what is path of dynamic libraries used at the run time
======================
ldd exe // show the used dynamic libs


Xiaobo Sun 2008-06-16 20:21 发表评论
]]>
վ֩ģ壺 ó| ν| °Ͷ| | | | ʯ| ߮| ɽ| ʶ| ϽϽ| | ʯ| Ȩ| | ˫| ѽ| | ʯ| | | | | пѷ| | | | | | | | ʲ| | ͸| | | | ܿ| | ֦| |