www.digitalmars.com         C & C++   DMDScript  

c++.beta - [bug] dmc.8.48.3 extern "C" and class member-functions

reply Nic Tiger <g_tiger progtech.ru> writes:
Looks like bug: extern "C" is applied to class member-functions.
This code compiled without error with previous DMC (8.41.5n) and was 
taken from MS DX8 SDK (dxtrans.h)

If this is proper behavior (according to standards), I would like to 
hear suggestions how to work around this.

Nic Tiger


dmc -c dx.cpp >1
------------------
       DXBASESAMPLE(const DWORD val) { *this = (*(DXBASESAMPLE *)&val); }
                  ^
dx.cpp(19) : Error: '?0' is already defined
       operator DWORD () const {return *((DWORD *)this); }
              ^
dx.cpp(20) : Error: '?0' is already defined
--- errorlevel 1

------------------
extern "C"{
   typedef unsigned long DWORD;
   typedef unsigned char BYTE;

   class DXBASESAMPLE
   {
   public:
       BYTE Blue;
       BYTE Green;
       BYTE Red;
       BYTE Alpha;
       DXBASESAMPLE() {}
       DXBASESAMPLE(const BYTE alpha, const BYTE red, const BYTE green, 
const BYTE blue) :
           Alpha(alpha),
           Red(red),
           Green(green),
           Blue(blue) {}
       DXBASESAMPLE(const DWORD val) { *this = (*(DXBASESAMPLE *)&val); }
       operator DWORD () const {return *((DWORD *)this); }
       DWORD operator=(const DWORD val) { return *this = *((DXBASESAMPLE 
*)&val); }
   }; // DXBASESAMPLE
}
Apr 14 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
Nic Tiger wrote:
 Looks like bug: extern "C" is applied to class member-functions.
 This code compiled without error with previous DMC (8.41.5n) and was 
 taken from MS DX8 SDK (dxtrans.h)

The extern statements apply to everything inside them, including the class members. To not have them apply, move the class declaration outside the extern statement.
Apr 14 2006
parent Nic Tiger <g_tiger progtech.ru> writes:
Walter Bright wrote:
 Nic Tiger wrote:
 Looks like bug: extern "C" is applied to class member-functions.
 This code compiled without error with previous DMC (8.41.5n) and was 
 taken from MS DX8 SDK (dxtrans.h)

The extern statements apply to everything inside them, including the class members. To not have them apply, move the class declaration outside the extern statement.

too bad... because it is not my code, but Microsoft's :( will have to insert two lines, and maybe put all these headers under version control system to track changes. thanks for early reply!
Apr 14 2006