Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #41081

Re: C++ complex.h protability

From "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>
Newsgroups comp.lang.c++
Subject Re: C++ complex.h protability
Date 2016-02-21 16:48 +0100
Organization A noiseless patient Spider
Message-ID <nacm34$9hk$1@dont-email.me> (permalink)
References <nach82$2uq$1@gwaiyur.mb-net.net>

Show all headers | View raw


On 21.02.2016 15:22, Marcel Mueller wrote:
> I have some compatibility issues regarding complex.h in an FFTW3
> application.
>
> In fact older C++ compilers required the include files with the .h
> extension (and no namespace std::), i.e.
>    #include <math.h>
>    #include <complex.h>

I believe the requirement had to be imposed by the FFTW3 headers.

No compilers can have imposed this requirement.


> This is deprecated but so far all relevant compilers supported the old
> header files for compatibility. The code is quite old (~15 years) and
> not namespace aware. I only upgraded to FFTW3 several years ago.
>
> But now I try to switch to a newer compiler (gcc 4.8) and this raises a
> conflict with the C99 compatibility header complex.h. Of course, this
> does not support the resulting type definition in fftw3.h (compiled with
> -E)
>    typedef __complex__<long double> fftwl_complex;
>
> The fftw3.h behaves differently when included from C++. This is an
> application specific patch.
>
> #ifdef __cplusplus
> /* In C++ mode prefer class complex<> */
> #include <complex.h>
> #  define FFTW_DEFINE_COMPLEX(R, C) typedef complex<R> C

This is wrong in two ways:

• Include of `<complex.h>`
   It doesn't define the name used. Should be just `<complex>`.

• Use of unqualified template `complex`.
   Should be `std::complex`.


> extern "C"
> {
> #else /* __cplusplus */
> /* If <complex.h> is included, use the C99 complex type.  Otherwise
>     define a type bit-compatible with C99 complex */
> #ifdef _Complex_I
> #  define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C
> #else
> #  define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2]
> #endif
> #endif /* __cplusplus */

This is a bit sloppy, and the comment is wrong, but should work.

Conclusion so far is that FFTW3 is coded by programmers who make trivial 
errors all over the place  –  so that where it works, it probably works 
by happenchance.


> This worked with older gcc 3.x, IBM icc and AFAIK Watcom.
>
> Is there an option to bring the old C++ complex.h compatibility back?
>
> I tried
>
> #include <complex>
> using std::complex;
>
> It seems to compile, but I am in doubt whether it is a good idea to mix
> old style and new style headers within a single compilation unit.

Above code is perfectly OK in an implementation file.

In the global namespace in a header the `using std::complex` can lead to 
unintended name collisions.


> Any suggestions, other than reworking all the old code for newer
> standard compliance?

I suggest switching to another FFT-library, one that works. :)

Barring that, submit a patch the fixes the errors noted above, and just 
hope that not too much more will go wrong.


Cheers & hth.,

- Alf

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

C++ complex.h protability Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-02-21 15:22 +0100
  Re: C++ complex.h protability "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-21 16:48 +0100
    Re: C++ complex.h protability Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-02-21 20:02 +0100
      Re: C++ complex.h protability Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-21 14:25 -0500
        Re: C++ complex.h protability Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-02-21 23:43 +0100
          Re: C++ complex.h protability Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-21 20:44 -0500
            Re: C++ complex.h protability Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-02-22 19:38 +0100
              Re: C++ complex.h protability Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 14:14 -0500
            Re: C++ complex.h protability Cholo Lennon <chololennon@hotmail.com> - 2016-02-22 16:36 -0300
              Re: C++ complex.h protability Ian Collins <ian-news@hotmail.com> - 2016-02-23 08:53 +1300
                Re: C++ complex.h protability Cholo Lennon <chololennon@hotmail.com> - 2016-02-22 17:03 -0300
                Re: C++ complex.h protability Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 15:16 -0500
                Re: C++ complex.h protability "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-22 21:38 +0100
                Re: C++ complex.h protability Cholo Lennon <chololennon@hotmail.com> - 2016-02-22 17:50 -0300
                Re: C++ complex.h protability Cholo Lennon <chololennon@hotmail.com> - 2016-02-22 18:09 -0300
                Re: C++ complex.h protability legalize+jeeves@mail.xmission.com (Richard) - 2016-02-22 21:20 +0000
                Re: C++ complex.h protability Öö Tiib <ootiib@hot.ee> - 2016-02-22 12:47 -0800
                Re: C++ complex.h protability Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 16:18 -0500
                Re: C++ complex.h protability Öö Tiib <ootiib@hot.ee> - 2016-02-22 13:51 -0800
                Re: C++ complex.h protability Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 16:57 -0500
                Re: C++ complex.h protability legalize+jeeves@mail.xmission.com (Richard) - 2016-02-22 22:16 +0000
                Re: C++ complex.h protability Öö Tiib <ootiib@hot.ee> - 2016-02-22 15:09 -0800
                Re: C++ complex.h protability Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-22 19:53 -0500
                Re: C++ complex.h protability Öö Tiib <ootiib@hot.ee> - 2016-02-22 23:23 -0800
        Re: C++ complex.h protability Robert Wessel <robertwessel2@yahoo.com> - 2016-02-22 02:54 -0600
      Re: C++ complex.h protability "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-21 22:05 +0100
        Re: C++ complex.h protability bartekltg <bartekltg@gmail.com> - 2016-02-23 10:55 +0100
          Re: C++ complex.h protability "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 19:45 +0100
            Re: C++ complex.h protability "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 19:55 +0100
            Re: C++ complex.h protability bartekltg <bartekltg@gmail.com> - 2016-02-23 20:41 +0100
              Re: C++ complex.h protability "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-23 22:26 +0100
    Re: C++ complex.h protability Christian Gollwitzer <auriocus@gmx.de> - 2016-02-22 08:16 +0100
      Re: C++ complex.h protability Öö Tiib <ootiib@hot.ee> - 2016-02-22 02:06 -0800
  Re: C++ complex.h protability Ian Collins <ian-news@hotmail.com> - 2016-02-22 09:00 +1300
    Re: C++ complex.h protability Marcel Mueller <news.5.maazl@spamgourmet.org> - 2016-02-21 23:51 +0100
      Re: C++ complex.h protability Öö Tiib <ootiib@hot.ee> - 2016-02-21 15:41 -0800
      Re: C++ complex.h protability "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2016-02-22 00:50 +0100

csiph-web