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

BUG: Cannot Access Static Data Members in Inline Assembly

This article was previously published under Q88092

On This Page

Expand all | Collapse all

SYMPTOMS

When trying to access static data members in a C++ program with inline assembly, the compiler may report the following errors:
error C2420: 'identifier' : illegal symbol in first operand 1
error C2415: improper operand type
The inline assembler cannot access static data members within a class member function. The sample code below demonstrates the problem.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

To access the static data member, assign the address of the data member to a temporary variable. The inline assembler can then access the data by loading the address from the temporary variable.

Below is code that demonstrates the problem and workaround.

Sample Code

   /* Compile options needed: /AS  for 16-bit
   *                          none for 32-bit
   */ 

   #include <stdio.h>

   class sample
   {
   public:

      static int value;
      sample();

   };

   int sample::value = 9;

   sample::sample()
   {

        __asm mov value,3             // C2420 and C2415 here
        __asm mov sample::value,ax    // C2420, C2414, C2400 on
                                      // this line

   //  For 16-bit workaround, uncomment next three lines.
   //     void * valueptr=&value;
   //     __asm mov bx, valueptr
   //     __asm mov [bx],3

   //  For 32-bit workaround, uncomment next three lines.
   //     void * valueptr=&value;
   //     __asm mov ebx, valueptr
   //     __asm mov [ebx],3
   }

   int main( void )
   {
      sample aSample;
      printf( "aSample.value = %d.\n", aSample.value );
      return 0;
   }
				

APPLIES TO
  • Microsoft C/C++ Professional Development System 7.0
  • Microsoft Visual C++ 1.0 Professional Edition
  • Microsoft Visual C++ 1.5 Professional Edition
  • Microsoft Visual C++ 2.0 Professional Edition
  • Microsoft Visual C++ 2.1
  • 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 KB88092
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