Showing posts with label c_cpp. Show all posts
Showing posts with label c_cpp. Show all posts

Saturday, November 15, 2008

complier supporting c99 complex

Recently, I have been surveying the operations of complex. From the c99 and C++0x standard draft, I get the information about the operations for a complex library. Besides, I also refer to boost math library for how to implement the complex.

BTW, the boost 1.3.6 seems does not implement all the operations supported by the c++0x draft.

And, I try to use vc2005, icc10.1, gcc4.2, dmc8.5 to experience the complex operations.
But vc2005 and gcc4.3 do not support the c99 complex.
And some operations in icc&win32 will be broken( throw a access violation when using cacos).
It seems that the dmc can do more work to complex operation. At least it will work normally for cacos operation.

The following is the sample testing in the dmc:

#include "stdio.h"
#include "math.h"
#include "complex.h"

void outputComplex(_Complex double rst )
{
printf("rst=%g+%gi\n", rst);
}


int main()
{


//_Complex double a_ = 1.0+ 5.0i;//error

_Complex double a__ = 1.0+ 5.0 * _Complex_I;

_Complex double a = 1.0+ 5.0 * I;

outputComplex(a);

complex double b = cacos(a);

double complex b_ = cacos(a);

outputComplex(b);

return 0;

}

////////
The following is the sample for icc10.1&win32

#include "stdio.h"
#include "math.h"
#include "complex.h"

void outputComplex(_Complex double rst )
{
printf("rst=%g+%gi\n", rst);//print in the readable format
}

int main()
{
float f__=1.0f;
isnan(f__);

_Complex double a;
_Complex double b;

a=1.0+5.0i;
a+=2.0+2.0i;//a=3+7i

_Complex double a_ = 1.0+ 5.0 * _Complex_I;

_Complex double a__ = 1.0+ 5.0 * I;

printf("a=%g+%gi\n",a);//print in the readable format
//a = cproj(a);

a = 1.0 + 2.0i;
b = cacos(a);//--
outputComplex(b);

return 0;
}

Tuesday, November 4, 2008

icc, vc2005, gcc4.2的参数入栈顺序和强制类型转化的一个case






icc, vc2005, gcc4.2的参数入栈顺序和强制类型转化的一个case

为方便描述, 想想如下的情况

有4个类型TA, TB,
              TA_meta, TB_meta,

存在如下的关系, 从TA可以转化成TA_meta, 
                       从TB可以转化成TB_meta,
                       从TA_meta<-->TB_meta,

...
TA:: operator TA_meta (const TA& );//从TA转化成TA_meta的函数
TA:: operator TA_meta (const TB& );//从TB转化成TA_meta的函数, 这里先把TB-->TB_meta, 然后吧TB_meta-->TA_meta

为方便我们需要引入另外一个类型 CC.
有一个函数如下:
foo(CC,  TA_meta);

调用者如下:
CC obj1;
TA ta;

foo(obj1, ta); //这里需要把ta--->ta对应的TA_meta

下面给出信息:
             |     编译器                   参数入栈顺序                            调用的转化函数  
------------------------------------------------------------------------------------
windows|     vc                         自右向左                             TA:: operator TA_meta (const TA& )    
             |     icc                         自左向右                             TA:: operator TA_meta (const TB& )---icc 疯了
-------------------------------------------------------------------------------------
linux      |     gcc                        自右向左                            TA:: operator TA_meta (const TA& )
            |      icc                         自左向右                            TA:: operator TA_meta (const TA& )






Sunday, November 2, 2008

how to compile gcc4.3.2

-----------编译-gcc 4.3.2----------
a.下载源代码

b.解压

c.查看里面的INSTALL文件夹, 里面有一些关于安装的帮助信息

--下面描述两个必要的组件GMP, GPFR
Installing GMP method1:
sudo apt-get install m4

method2:------recommended
download the src.
unzip.
--to the following steps, please look into the INSTALL file in the source.
./configure
make
make check
make install: the default target path is /usr/local


Installing GPFR
download the src.
unzip.
--to the following steps, please look into the INSTALL file in the source.
./configure
make
make check
make install: the default target path is /usr/local

------
from the prerequisities of gcc. you may be need to install gawk (sudp apt-get install gawk )too.



d.configure进行注册

假设加压后的源代码目录是 gcc-4.3.2
这个目录下还有不少别的目录 比如INSTALL, gcc, ...
进入这个目录,执行如下操作(可能需要管理员权限,即加sudo )

% mkdir objdir
% cd objdir
sudo ./../configure --enable-languages=c,c++
--prefix=/usr/local/gcc-4.3.2 --enable-shared --with-system-zlib
--without-included-gettext --enable-threads=posix --enable-nls
--enable-libstdcxx-debug --enable-mpfr --enable-targets=all
--enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu
--target=i486-linux-gnu --disable-multilib

注意
1. 这里是在objdir目录下,所以使用的是gcc-4.3.2目录下的configure
2. 关于configure的选项我 试了很多个, 也用了好长时间,才发现这个可用。这里给出一些如何发现这个选项的信息。
一开始我的电脑上转的是 gcc4.2.3. 后来我又更新到了gcc.4.3.2. 以下是我看到的已经安装(通过apt-get)的gcc的选项
//--------------gcc 4.3.2 -v 查看选项------------------
Using built-in specs.
Target: i486-linux-gnu
Configured
with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.2-1ubuntu8'
--with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--enable-mpfr --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu8)
//----------------

//----------gcc4.2.2 -v 查看选项----------------------
Using built-in specs.
Target: i486-linux-gnu
Configured
with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc
--enable-mpfr --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)

你可以把上面的一些选项直接拿过来用比如
--enable-languages=c,c++,fortran,objc,obj-c++
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--enable-libstdcxx-debug
--enable-mpfr --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu

3. 必须加上--disable-multilib否则会发生编译错误

4. 这里你必须指定
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
否则会错误,在我的机器上他自己探测为i686-linux-gnu. 这会导致错误。

5. prefix 选项你指定了你想把gcc4.3.2安装到哪一个目录下, 你必须/最好指定

e. test. 参考INSTALL文件夹下面的信息

f. sudo make install
to install gcc4.3.2 to the prefix directory which is specified when configure.

-------------------------
以上是 在我的机器上安装的 过程。。

我想不同的机器 肯定会不同。。