Inline compiler error Build error: - C2400: syntax error of the built-in assembler in the second operand; found 'newline'

I tested C code and came across this weird compiler error

The following code will not compile

#include<stdio.h> void main() { int length=6; __asm { mov eax,length } } 

Visual Studio reports the following error

 test.c(7) : error C2400: inline assembler syntax error in 'second operand'; found 'newline' 

However, I noticed that if I changed the variable name to something else, say lengths , then everything was fine, the following code compiles without difficulty

 #include<stdio.h> void main() { int lengths=6; __asm { mov eax,lengths } } 

I tried with other compilers such as Digital Mars and Intel Compiler, but everywhere the first code cannot be compiled.

What could be the problem? Is there another definition for length elsewhere.

I would also like to add that this is a single file, not a project, so there can be no multiple declarations.

+7
c visual-c ++ compiler-errors
source share
2 answers

See here: http://msdn.microsoft.com/en-US/library/wxh0awwe%28v=vs.80%29.aspx

In particular

The LENGTH, SIZE, and TYPE statements have limited value in the inline assembly. They cannot be used at all with the DUP statement (because you cannot define data using directives or MASM statements). But you can use them to find the size of variables or types of C or C ++:

+5
source share

I think the reason may be because length is a member function

MSDN also says:

The LENGTH , SIZE, and TYPE statements have limited value in the inline assembly. They cannot be used at all with the DUP statement (because you cannot define data using directives or MASM statements). But you can use them to find the size of variables or types of C or C ++:

The LENGTH operator can return the number of elements in an array. This returns a value of 1 for variables without an array.

+7
source share

All Articles