Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better C++ support (std::complex) #254

Open
maazl opened this issue Aug 31, 2021 · 3 comments
Open

Better C++ support (std::complex) #254

maazl opened this issue Aug 31, 2021 · 3 comments

Comments

@maazl
Copy link

maazl commented Aug 31, 2021

Using fftw3 in a C++ application requires thunking layers because the array data type R C[2] is not compatible to std::complex at language level. They are guaranteed to be binary compatible, but C++ does not even allow casts between arrays and classes.
So pointer conversions are required at several places. This makes the code poorly readable, error prone and may even prevent some compiler optimizations due to the required reinterpret casts.

It should be possible to force fftw3.h to use std::complex similar to the support for C99 _Complex.

@maazl
Copy link
Author

maazl commented Aug 31, 2021

I added a PR (#255) with a possible solution.

@Lqlsoftware
Copy link
Contributor

Lqlsoftware commented Sep 2, 2021

Since FFTW is a pure C library, APIs should be wrapped by extern "C" {}. With the addition of std::complex, there should be an implementation of the whole complex interface to do the reinterpret casts... like the f77 interface did.

@maazl
Copy link
Author

maazl commented Sep 2, 2021

Hmm, yes the injection of C++ code in the header is not that pretty. A separate include for this purpose might be a better solution than a macro like FFTW_cpp_complex.
However, there is no need to wrap any function. Replacing the definition of FFTW_DEFINE_COMPLEX is sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants