From: Renzr on 20 May 2010 12:32 Hi, I had to call a C++ library using std::complex<double> as its complex number type. But I want to use C99 complex number in my code. When I include the <complex.h> head file, it will lead to a lots of errors. So, is it possible to using C99 complex number in my C++ code to call a C++ library using std::complex<double> as its complex number? Kind regards, Zhengyong -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Vaclav Haisman on 20 May 2010 17:04 Renzr wrote, On 21.5.2010 5:32: > Hi, > I had to call a C++ library using std::complex<double> as its complex > number type. > But I want to use C99 complex number in my code. When I include the > <complex.h> head file, it will lead to a lots of errors. C++ compiler is not C99 compiler, even though some compilers like GCC support various C99 features in C++ code. > > So, is it possible to using C99 complex number in my C++ code to call > a C++ library using std::complex<double> as its complex number? Why? You are doing C++, do with the C++ standard library. If you need it just to pass complex numbers to C99 library functions then I guess you will have to write some kind of wrapper functions that pass the rela and imaginary part separatelly to the C99 function which combines them to a _Complex double value and passes them further to C99 function: foo.cpp: extern "C" void foo (double re, double im); bar.c: #include <complex.h> void foo (double re, double im) { _Complex double c = re + I * im; some_c99_func (c); } -- VH -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Nick Hounsome on 26 May 2010 17:35 On 21 May, 04:32, Renzr <renzhengy...(a)gmail.com> wrote: > Hi, > I had to call a C++ library using std::complex<double> as its complex > number type. > But I want to use C99 complex number in my code. When I include the > <complex.h> head file, it will lead to a lots of errors. > > So, is it possible to using C99 complex number in my C++ code to call > a C++ library using std::complex<double> as its complex number? Interestingly the latest draft (n3090) of the new standard requires ALL the C headers (including complex.h and tgmath.h) and even specifies the usual <ccomplex> and <ctgmath> but does not list _Complex as a fundamental type. Either this is an omission and _Complex IS a fundamental type. In this case extensive changes would be required regarding standard conversions etc. OR _Complex IS std::complex in which case this should be stated OR _Complex isn't supported in which case wwhy support the headers? Also there is no mention of the complex macro which will cause no end of problems in mixed code unless you include the C headers first and then undef complex. IMHO the practical answer must be that _Complex is mapped to std::complex even though the "proper" solution is probably that it be a full type in C++. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: information for find Next: C++ STL vectors - pointer to Vectors: do we need them? |