Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler Error in inline Assembly error:- C2400: inline assembler syntax error in 'second operand'; found 'newline'

I was testing some C code and came across this strange compiler error

The following code would 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 if I changed the name of the variable to something else say lengths then everything was fine, the following code compiles without any 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 can be the issue ? Is there another definition for length elsewhere.

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

like image 745
Extreme Coders Avatar asked Nov 18 '13 17:11

Extreme Coders


2 Answers

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

Also MSDN says:

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

The LENGTH operator can return the number of elements in an array. It returns the value 1 for non-array variables.

like image 171
Rahul Tripathi Avatar answered Oct 05 '22 02:10

Rahul Tripathi


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

Specifically

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

like image 24
Scotty Bauer Avatar answered Oct 05 '22 02:10

Scotty Bauer