BUG: Function Style Conversion Incorrectly Generates Errors

Last reviewed: July 24, 1997
Article ID: Q115705
The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft Visual C++ for Windows, versions 1.0, 1.5 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 4.0, 4.1, 4.2,

         5.0
    

SYMPTOMS

When calling a class conversion function within a macro, as shown in the code below, the compiler may incorrectly generate the following errors:

  error C2061: syntax error : identifier 'timeVal'
  error C2066: cast to function type is illegal
  error C2059: syntax error : ')'

RESOLUTION

Following are two possible workarounds for this problem:

  • Use temporary variables to hold an intermediate result.

          unsigned int tmp1, tmp2;
    

          tmp1 = WORD(timeVal);
          tmp2 = WORD(dateVal);
          m_dwVal = MAKELONG(tmp1, tmp2);
    

-or-
  • Use a type cast operator instead of a conversion operator.

          m_dwVal = MAKELONG((WORD)timeVal, (WORD)dateVal);
    

STATUS

Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following sample code demonstrates this problem.

Sample Code

   /* Compile options needed: /c
   */

   typedef unsigned short      WORD;
   typedef unsigned long       DWORD;

   #define LONG long

   #define MAKELONG(low, high) ((LONG)(((WORD)(low)) |  \
                   (((DWORD)((WORD)(high))) << 16)))

   class CMyDate
   {
   public:
      operator WORD()
      {
         return m_wVal;
      }

   private:
      WORD m_wVal;
   };

   class CMyTime
   {
   public:
      operator WORD()
      {
         return m_wVal;
      }

   private:
      WORD m_wVal;
   };

   class CMyDateTime
   {
      CMyDateTime(CMyDate dateVal, CMyTime timeVal)
      {
         m_dwVal = MAKELONG(WORD(timeVal), WORD(dateVal));

      // This call works in both, even though it is identical.

         m_dwVal= MAKELONG(timeVal.operator WORD(), dateVal.operator
                  WORD());
      }

    private:
      DWORD m_dwVal;
   };


Additional query words: 8.00 8.00c 9.00
Keywords : CPPIss vcbuglist400 vcbuglist500
Version : 1.0 1.5 2.0 4.0 4.1 4.2 5.0
Platform : NT WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.