473,513 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

f2c's abs conflicts with <complex> abs

Hi,

I am using CLAPACK to do lots of matrix operations, but this is done on
complex matrices. There I also need to work with normal complex
operators, I use also the standard complex library. Unfortunately this
one conflicts with some stuff in f2c.h needed to run CLAPACK. Examples
are that f2c.h declares a variable complex that fights with everything
from the standard complex header. Most errors I got rid of by dumping
all the Lapack headers in a separate namespace, but now I still did not
resolve one last problem. And I think it might be basic C++.

Assume the following file

** begin code.cpp **

#include <iostream>
#include <complex>

using namespace std;

// putting lapack in a namespace

namespace lapack {
extern "C" {
#include "f2c.h"
#include "clapack.h"
}
}

int main(void) {

cout << abs(complex<double>(0.,1.)) << endl;

/* here comes more code using lapack::(functions) */

return 1;
}

** end code.cpp **

Compiling this gives an error of the sort

error: no match for ‘operator>=’ in ‘std::complex<double>(0.0, 1.0e+0) >= 0’

because fc2.h contains a line
#define abs(x) ((x) >= 0 ? (x) : -(x))

But abs is also defined in the complex header, but preprocessor
directives win over function calls I think.

So I guess you see my question.
How can I circumvent this problem?

Regards
Klaas
Oct 31 '06 #1
3 3537
Klaas Vantournhout wrote:
I am using CLAPACK to do lots of matrix operations, but this is done
on complex matrices. There I also need to work with normal complex
operators, I use also the standard complex library. Unfortunately
this
one conflicts with some stuff in f2c.h needed to run CLAPACK.
Examples
are that f2c.h declares a variable complex that fights with everything
from the standard complex header. Most errors I got rid of by dumping
all the Lapack headers in a separate namespace, but now I still did
not resolve one last problem. And I think it might be basic C++.

Assume the following file

** begin code.cpp **

#include <iostream>
#include <complex>

using namespace std;

// putting lapack in a namespace

namespace lapack {
extern "C" {
#include "f2c.h"
#include "clapack.h"
}
}

int main(void) {

cout << abs(complex<double>(0.,1.)) << endl;

/* here comes more code using lapack::(functions) */

return 1;
}

** end code.cpp **

Compiling this gives an error of the sort

error: no match for ‘operator>=’ in ‘std::complex<double>(0.0,
1.0e+0) >= 0’

because fc2.h contains a line
#define abs(x) ((x) >= 0 ? (x) : -(x))

But abs is also defined in the complex header, but preprocessor
directives win over function calls I think.

So I guess you see my question.
How can I circumvent this problem?
Right after #include "f2c.h" do

#undef abs

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 31 '06 #2
Right after #include "f2c.h" do
>
#undef abs

V
I've been thinking about that indeed, but then just wondered if this
solution doesn't influence the working of lapack, there it is based on
this function.
Oct 31 '06 #3
Klaas Vantournhout wrote:
>Right after #include "f2c.h" do

#undef abs

V

I've been thinking about that indeed, but then just wondered if this
solution doesn't influence the working of lapack, there it is based on
this function.
It's not a function. It's a macro here. If you have doubts, move the
#undef _after_ the inclusion of 'lapack'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1749
by: Peng Yu | last post by:
http://www.digitalmars.com/rtl/complex.html The above the specification of complex.h, but it seem that g++(3.3) hasn't fully support it yet. I wonder where I can find the specifications of...
7
4110
by: Don Tucker | last post by:
Hello, I have the following test program that I can compile with gcc, but when I try to compile with the portland group compiler, pgcc, I get a stream of errors. #include <stdio.h> #include...
2
9770
by: Arvid Requate | last post by:
Hello, I'd like to understand why the following code does not compile. It looks like a strangeness in connection with overload resolution for the <complex> header: The conversion operator...
17
3704
by: Julian V. Noble | last post by:
Dear C Mavens, I am writing a Computing Prescription for CiSE on complex arithmetic. I would like to be sure that I do not include any gaffes about C99--especially about what is in the header...
3
6133
by: J.M. | last post by:
I have data in a double array of length 2N, which actually represents complex numbers with real and imaginary parts interlaced. In other words, elements in this array with even indices represents...
5
6036
by: jeremit0 | last post by:
I'm trying to sort a vector<complex<double and can't figure it out. I recognize the problem is that there isn't a default operator< for complex data types. I have written my own operator and can...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.