Article ID: 115705 - Last Review: July 5, 2005 - Revision: 2.1

FIX: Function Style Conversion Incorrectly Generates Errors

This article was previously published under Q115705

On This Page

Expand all | Collapse all

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 that this is a bug in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ .NET.

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;
};


				

APPLIES TO
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 1.5 Professional Edition
  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 4.1 Subscription
  • Microsoft Visual C++ 4.2 Professional Edition
  • Microsoft Visual C++ 5.0 Standard Edition
  • Microsoft Visual C++ 6.0 Service Pack 5
Keywords: 
kbbug kbcompiler kbcpponly kbfix kbnoupdate KB115705
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations