On 23.02.2016 10:55, bartekltg wrote:
> On 21.02.2016 22:05, Alf P. Steinbach wrote:
>> On 21.02.2016 20:02, Marcel Mueller wrote:
>>> On 21.02.16 16.48, Alf P. Steinbach wrote:
>>>>> 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.
>>>
>>> 15 to 20 years ago all you get by #include <math> was "File not found".
>>
>> There is no standard library header <math> and never has been.
>>
>> There is a C++ standard library header <complex>. It's different from
>> <ccomplex> and <complex.h>.
>
> It has changed ;-)
No. Not as far as I know. :)
> "26.4.11 Header <ccomplex> [ccmplx]
> 1 The header behaves as if it simply includes the header <complex>."
Points to understand the above quote, which is of C++11 §26.4.10/1:
• The header <ccomplex> is not the header <complex>.
• The header <ccomplex> is the basic C++ variant of the /C header/
<complex.h>. It places the C declarations in namespace std. It may also
place them in the global namespace.
• The /C++ header/ <complex.h>, distinct from the C header <complex.h>
(same name, yes), is defined in terms of <ccomplex> instead of directly
in terms of the C header. The C++ header <complex.h> provides the same
contents as <ccomplex> except that it provides this content in the
global namespace. It may also provide the contents in the std namespace.
And yes, I agree, the complexity of this is really ridiculous. The
original C++98 idea was evidently to not-so-subtly-at-all encourage a
move from “foo.h” headers to header names without filename extensions
“cfoo”. At that time C++ <ccomplex> was not allowed to pollute the
global namespace. But that did not sit well with compiler vendors, who
saw no reason to jump through hoops with additional extreme complexity,
with no evident advantage other than maybe supporting some idealistic
notions about filenames, so with C++11 the rules were changed to make
the <ccomplex> and <complex.h> requirements symmetric (and ditto for all
other such header pairs), incidentally making the whole thing
/meaningless/. So, just include <complex.h>, and forget about the
<ccomplex> complexity, so to speak – but remember that this is the
/C++ version/ of <complex.h>, and so it can, at the implementation's
discretion, make code that uses std:: qualifications compile, even
though that will not compile with some other compiler. :(
Relevant:
C++11 §
17.6.1.2:
<quote>
Except as noted in Clauses 18 through 30 and Annex D, the contents of
each header cname shall be the same as that of the corresponding header
name.h, as specified in the C standard library (1.2) or the C Unicode
TR, as appropriate, as if by inclusion. In the C ++ standard library,
however, the declarations (except for names which are defined as macros
in C) are within namespace scope (3.3.6) of the namespace std. It is
unspecified whether these names are first declared within the global
namespace scope and are then injected into namespace std by explicit
using-declarations (7.3.3).
</quote>
> BTW, since, I think, c++11 there is a binary compatibility with C
> complex. I think this is because of :
>
> "
> 26.4:
> ...
> If z is an lvalue expression of type cv std::complex<T> then:
> (4.1) — the expression reinterpret_cast<cv T(&)[2]>(z) shall be
> well-formed,
> (4.2) — reinterpret_cast<cv T(&)[2]>(z)[0] shall designate the real part
> of z, and
> (4.3) — reinterpret_cast<cv T(&)[2]>(z)[1] shall designate the imaginary
> part of z.
> Moreover, if a is an expression of type cv std::complex<T>* and the
> expression a[i] is well-defined for an
> integer expression i, then:
> (4.4) — reinterpret_cast<cv T*>(a)[2*i] shall designate the real part of
> a[i], and
> (4.5) — reinterpret_cast<cv T*>(a)[2*i + 1] shall designate the
> imaginary part of a[i].
> "
Yes. That compatibility is the whole point of the above wording.
> [snip]
> I think the problem is with libraries based on fortran (with C
> interface). Then reinterpreted cast is needed, but at least
> should work.
Oh. I didn't think of that.
Cheers!,
- Alf