complex setters implemented differently between Linux and Windows

L

liam_herron

This might not be the right place for this post, but maybe I can get a
clarification on
what the C++ standard says.


g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)
MS VC++ (2003): Version 7.1.3088


I have created a wrapper for the complex double so that I can forward
declare it
in other classes. Here is what I have had to do in my setters:


//-------------------------------------------------------------------------
inline
double ComplexDouble::real(double realPart)
//-------------------------------------------------------------------------
{
#ifdef WIN32
return impl_.real(realPart);
#else //LINUX
return ( impl_.real() = realPart );
#endif
}

//-------------------------------------------------------------------------
inline
double ComplexDouble::imag(double imagPart)
//-------------------------------------------------------------------------
{
#ifdef WIN32
return impl_.imag(imagPart);
#else //LINUX
return ( impl_.imag() = imagPart );
#endif
}


For some reason my version of g++ returns a writable reference as
opposed to passing the
parameter to set in as a method argument. I am not sure here but I
believe that VC++ is
implementing the standard correctly. Could this be a conflict with
the C standard or
something? In my experience, g++ usually wins the "closer to C++
standard" battles
but it does NOT appear to be the case here.

Thanks in advance,
Liam
 
M

Marco Manfredini

liam_herron said:
This might not be the right place for this post, but maybe I can get a
clarification on
what the C++ standard says.


g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)
MS VC++ (2003): Version 7.1.3088


I have created a wrapper for the complex double so that I can forward
declare it
in other classes. Here is what I have had to do in my setters:


//-------------------------------------------------------------------------
inline
double ComplexDouble::real(double realPart)
//-------------------------------------------------------------------------
{
#ifdef WIN32
return impl_.real(realPart);
#else //LINUX
return ( impl_.real() = realPart );
#endif
}

Both are wrong. The current standard mandates, that real and imag are
declared as this:
template<class T>
class complex {
....
T real() const;
T imag() const;
....
};
 
G

gpderetta

Both are wrong. The current standard mandates, that real and imag are
declared as this:
template<class T>
class complex {
...
T real() const;
T imag() const;
...

};

But the next standard will require it {real|imag}(T) (in addition to
being layout compatible with C complex and T[2]). See the resolution
to the standard library issue 387.

GCC standard library implements an older proposed resolution of the
issue, and probably retains it for ABI reasons.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top