Refer to
http://stackoverflow.com/questions/399704/xml-parser-for-c
Due to a thread in expat, expat has a little higher benchmark than libxml2. But just a little.
Also another xml parser writer in C++ is mentioned - http://xerces.apache.org/xerces-c/
The xml parser won't be a key factor for our project.
Currently, expat is adopted in aoo/symphony. It's based on stream.
http://baike.baidu.com/view/4997565.htm
Tuesday, July 31, 2012
Friday, July 27, 2012
STL VS StdLib
Look around stack overflow and get some knowledge on STL and StdLib.
Quote from below link:
http://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all-about/5205571#5205571
The "STL"(C++ Standard Template Library) was written by Alexander Stepanov in the days long before C++ was standardized. It's used as library of C++.
The original STL is now often called "an implementation of the C++ Standard Template Library" (rather backwards to actual history!), in the same way that your Microsoft Visual Studio or GCC ships an implementation of the C++ Standard Library. But the "Standard Template Library" and the "Standard Library" are not the same thing.
Don't refer to the C++ Standard Library as "STL". Maybe try stdlib.
Some additional info:
In addition, there are some STL-like libraries that are in fact implementations of the original STL, not the C++ Standard Library. Until recently, STLPort was one of them (and even there, the confusion abounds!).
My comments: see what's from STLPort site:
STLport is a multiplatform C++ Standard Lib implementation.(Still stdlib? Maybe check the confusion later.)
STL has hash_map while C++ Standard Lib doesn't.
STL has no std namespace (IIRC) while C++ Standard Lib does.
Quote from below link:
http://stackoverflow.com/questions/5205491/whats-this-stl-vs-c-standard-library-fight-all-about/5205571#5205571
The "STL"(C++ Standard Template Library) was written by Alexander Stepanov in the days long before C++ was standardized. It's used as library of C++.
The original STL is now often called "an implementation of the C++ Standard Template Library" (rather backwards to actual history!), in the same way that your Microsoft Visual Studio or GCC ships an implementation of the C++ Standard Library. But the "Standard Template Library" and the "Standard Library" are not the same thing.
Don't refer to the C++ Standard Library as "STL". Maybe try stdlib.
C++ standard includes much more things outside the STL, so the term "C++ standard library" is more correct (and is what's actually used by the standards documents).
Some additional info:
In addition, there are some STL-like libraries that are in fact implementations of the original STL, not the C++ Standard Library. Until recently, STLPort was one of them (and even there, the confusion abounds!).
My comments: see what's from STLPort site:
STLport is a multiplatform C++ Standard Lib implementation.(Still stdlib? Maybe check the confusion later.)
STL has hash_map while C++ Standard Lib doesn't.
STL has no std namespace (IIRC) while C++ Standard Lib does.
Some components of the C++ standard library include STL components like vector, list and algorithms like copy and swap.
My comments: It seems that std::string isn't included in STL? Just see the "std::" before string.
My comments: It seems that std::string isn't included in STL? Just see the "std::" before string.
Thursday, July 12, 2012
Stl containers
1. Map's insert
Because map containers do not allow for duplicate key values, the insertion operation checks for each element inserted whether another element exists already in the container with the same key value, if so, the element is not inserted and its mapped value is not changed in any way.
Thus, below code's output will be 2 instead of 3.
map<int, int> iMap;
iMap.insert(map<int, int>::value_type(1, 2));
map<int, int>::iterator it = iMap.find(1);
if (it != iMap.end())
{
iMap.insert(map<int, int>::value_type(1, 3));
it = iMap.find(1);
if (it != iMap.end())
{
cout << it->second << endl;
}
}
Something additional is its return value:
returns a pair, with its member pair::first set to an iterator pointing to either the newly inserted element or to the element that already had its same key in the map. The pair::second element in the pair is set totrue if a new element was inserted or false if an element with the same key existed.
It means you can use its return value's second to check if this insertion is a success or not.
Because map containers do not allow for duplicate key values, the insertion operation checks for each element inserted whether another element exists already in the container with the same key value, if so, the element is not inserted and its mapped value is not changed in any way.
Thus, below code's output will be 2 instead of 3.
map<int, int> iMap;
iMap.insert(map<int, int>::value_type(1, 2));
map<int, int>::iterator it = iMap.find(1);
if (it != iMap.end())
{
iMap.insert(map<int, int>::value_type(1, 3));
it = iMap.find(1);
if (it != iMap.end())
{
cout << it->second << endl;
}
}
Something additional is its return value:
returns a pair, with its member pair::first set to an iterator pointing to either the newly inserted element or to the element that already had its same key in the map. The pair::second element in the pair is set totrue if a new element was inserted or false if an element with the same key existed.
It means you can use its return value's second to check if this insertion is a success or not.
What do "(void) var;" and "(void) 0;" mean?
1. (void)var
It is seen often in AOO. What does it mean?
Maybe to avoid a compilation warning because "var" isn't used?
From:http://stackoverflow.com/questions/6145548/what-is-the-purpose-of-the-statement-voidc
2. (void) 0
From: http://stackoverflow.com/questions/2198950/why-is-void-0-a-no-operation-in-c-and-c
For __noop in MS, see below quotation from MSDN
http://msdn.microsoft.com/en-us/library/s6btaxcs%28VS.80%29.aspx
// compiler_intrinsics__noop.cpp
// compile with or without /DDEBUG
#include <stdio.h>
#if DEBUG
#define PRINT printf_s
#else
#define PRINT __noop
#endif
int main() {
PRINT("\nhello\n");
}
3. (void) func()
Consider the following code snippet:
int func(void);
...
(void) func();
Here I'm casting the return value of the function to void. That certainly makes it look like there's a data type called void. In reality, this sort of cast is a special case; it tells the compiler that you want to throw away the return value of the function. The compiler would do that anyway if you hadn't included the cast to void, so cast to void is unnecessary. Some people use it as idiom to tell lint, the compiler, and [most importantly] the maintenance programmers that they knew the function returns a value but deliberately decided to ignore it.
It is seen often in AOO. What does it mean?
Maybe to avoid a compilation warning because "var" isn't used?
From:http://stackoverflow.com/questions/6145548/what-is-the-purpose-of-the-statement-voidc
2. (void) 0
Q: I have seen debug printfs in glibc which internally is defined as
(void) 0, if NDEBUG is defined. Likewise the __noop for Visual C++ compiler is there too. The former works on both GCC and VC++ compilers, while the latter only on VC++. Now we all know that both the above statements will be treated as no operation and no respective code will be generated; but here's where I've a doubt.
In case of
__noop, MSDN says that it's a intrinsic function provided by the compiler. Coming to (void) 0 ~ Why is it interpreted by the compilers as no op? Is it a tricky usage of the C language or does the standard say something about it explicity? Or even that is something to do with the compiler implementation?
A:
(void)0 (+;) is a valid, but 'does-nothing' C++ expression, that's everything. It doesn't translate to the no-op instruction of the target architecture, it's just an empty statement as placeholder whenever the language expects a complete statement (for example as target for a jump label, or in the body of anif clause).For __noop in MS, see below quotation from MSDN
http://msdn.microsoft.com/en-us/library/s6btaxcs%28VS.80%29.aspx
The __noop intrinsic specifies that a function should be ignored and the argument list be parsed but no code be generated for the arguments. It is intended for use in global debug functions that take a variable number of arguments.
// compile with or without /DDEBUG
#include <stdio.h>
#if DEBUG
#define PRINT printf_s
#else
#define PRINT __noop
#endif
int main() {
PRINT("\nhello\n");
}
3. (void) func()
Consider the following code snippet:
int func(void);
...
(void) func();
Here I'm casting the return value of the function to void. That certainly makes it look like there's a data type called void. In reality, this sort of cast is a special case; it tells the compiler that you want to throw away the return value of the function. The compiler would do that anyway if you hadn't included the cast to void, so cast to void is unnecessary. Some people use it as idiom to tell lint, the compiler, and [most importantly] the maintenance programmers that they knew the function returns a value but deliberately decided to ignore it.
Wednesday, July 11, 2012
something about compiler and linker
Q: -DDEBUG
A: in code, you can use below code special for debug version
#ifdef DEBUG
// do sth for debug
#else
// do sth for release
#endif
Q: -DSTLPORT_VERSION=400
A: define STLPORT_VERSION=400
A: in code, you can use below code special for debug version
#ifdef DEBUG
// do sth for debug
#else
// do sth for release
#endif
Q: -DSTLPORT_VERSION=400
A: define STLPORT_VERSION=400
Tuesday, July 10, 2012
Monday, July 9, 2012
Tips on emacs
M-x find-name-dired RET
Press "t" to select all files found
Press "Q" (shift Q) to start the search/replace
Press "t" to select all files found
Press "Q" (shift Q) to start the search/replace
Wednesday, July 4, 2012
makefile
Some tips on debug makefile
1. make -p|tee make.out
-p, --print-data-base Print make's internal database.
2. make -n
-d Print lots of debugging information.
--debug[=FLAGS] Print various types of debugging information.
1. make -p|tee make.out
-p, --print-data-base Print make's internal database.
2. make -n
-n, --just-print, --dry-run, --recon
Don't actually run any commands; just print them.
3. make -d
-d Print lots of debugging information.
--debug[=FLAGS] Print various types of debugging information.
Tuesday, July 3, 2012
ZZ ranlib
linux下编译静态库的时候,ar不带任何选项打包成.a文件后,对其进行ranlib操作有什么用,如果不进行ranlib操作会有什么后果,我编译的时候没用这步操作也能正常运行,请达人给讲解一下。谢谢。
http://www.linuxsir.org/main/doc/gnumake/GNUmake_v3.80-zh_CN_html/make-11.html
更新静态库的符号索引表
本小节的内容相对简单。前边提到过,静态库文件需要使用“ar”来创建和维护。当给静态库增建一个成员时(加入一个.o文件到静态库中),“ar”可直接将需要增加的.o文件简单的追加到静态库的末尾。之后当我们使用这个库进行连接生成可执行文件时,链接程序“ld”却提示错误,这可能是:主程序使用了之前加入到库中的.o文件中定义的一个函数或者全局变量,但连接程序无法找到这个函数或者变量。
这个问题的原因是:之前我们将编译完成的.o文件直接加入到了库的末尾,却并没有更新库的有效符号表。连接程序进行连接时,在静态库的符号索引表中无法定位刚才加入的.o文件中定义的函数或者变量。这就需要在完成库成员追加以后让加入的所有.o文件中定义的函数(变量)有效,完成这个工作需要使用另外一个工具“ranlib”来对静态库的符号索引表进行更新。
我们所使用到的静态库(文档文件)中,存在这样一个特殊的成员,它的名字是“__.SYMDEF”。它包含了静态库中所有成员所定义的有效符号(函数名、变量名)。因此,当为库增加了一个成员时,相应的就需要更新成员“__.SYMDEF”,否则所增加的成员中定义的所有的符号将无法被连接程序定位。完成更新的命令是:
ranlib ARCHIVEFILE
通常在Makefile中我们可以这样来实现:
libfoo.a: libfoo.a(x.o) libfoo.a(y.o) ...
ranlib libfoo.a
它所实现的是在更新静态库成员“x.o”和“y.o”之后,对静态库的成员“__.SYMDEF”进行更新(更新库的符号索引表)。
如果我们使用GNU ar工具来维护、管理静态库,我们就不需要考虑这一步。GNU ar本身已经提供了在更新库的同时更新符号索引表的功能(这是默认行为,也可以通过命令行选项控制ar的具体行为。可参考 GNU ar工具的man手册)。
Subscribe to:
Posts (Atom)