BUG: Cannot Access Static Data Members in Inline AssemblyLast reviewed: July 21, 1997Article ID: Q88092 |
The information in this article applies to:
SYMPTOMSWhen 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 typeThe inline assembler cannot access static data members within a class member function. The sample code below demonstrates the problem.
STATUSMicrosoft has confirmed this to be a bug in the products listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONTo 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 some 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; } |
Additional query words: 8.00 8.00c 9.00 10.00 10.10 10.20
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |