Reputation:
So I have this code here, which does not let me compile my dll, It just returns the error above.
void Math::AngleVectors(const Vector &angles, Vector *forward, Vector *right, Vector *up)
{
auto SinCos = [](float flRadians, float* pflSine, float* pflCosine)
{
__asm
{
fld DWORD PTR[flRadians]
fsincos
mov edx, DWORD PTR[pflCosine]
mov eax, DWORD PTR[pflSine]
fstp DWORD PTR[edx]
fstp DWORD PTR[eax]
} // here it says the error "an 'asm' declaration is not allowed here"
};
[...]
}
I do not know how to solve this, does anyone know what's wrong here?
I am targeting x86
Upvotes: 2
Views: 610
Reputation: 10946
Unfortunately, you can't do what you're trying to do. Due to security concerns, inline assembly isn't supported inside a lambda in Visual Studio 2019:
Paraphrasing the answer (it's detailed), you must put the asm in a named function and have the lambda call that:
void SinCosAsm(float flRadians, float* pflSine, float* pflCosine) {
__asm
{
fld DWORD PTR[flRadians]
fsincos
mov edx, DWORD PTR[pflCosine]
mov eax, DWORD PTR[pflSine]
fstp DWORD PTR[edx]
fstp DWORD PTR[eax]
}
//...
}
void Math::AngleVectors(const Vector &angles, Vector *forward, Vector *right, Vector *up)
{
auto SinCos = [](float flRadians, float* pflSine, float* pflCosine)
{
SinCosAsm(flRadians, pflSine, pflCosine);
};
[...]
}
Upvotes: 3