sourcepawn
sourcepawn copied to clipboard
trigger warning when using "enum struct" with "view_as"
Compiler version: 1.12.0.7134
I think it is now possible to customize a “Vector3” to interact with any function that uses “float[3]”, but a warning will be prompted when using view_as.
#define AsFloat(%1) view_as<float>(%1)
enum struct Vector3
{
float x;
float y;
float z;
void Normalized()
{
NormalizeVector(AsFloat(this),AsFloat(this));//warning 229: index tag mismatch (symbol "this")
}
}
public void OnPluginStart()
{
float f1[3] = {0.0,100.0,0.0};
Vector3 v1= {100.0,0.0,0.0};
AddVectors(f1,AsFloat(v1),AsFloat(v1)); //warning 229: index tag mismatch (symbol "v1")
f1 = AsFloat(v1); //warning 229: index tag mismatch (symbol "v1")
PrintToServer("f1 = %f %f %f",f1[0],f1[1],f1[2]);//f1 = 100.000000 100.000000 0.000000
NormalizeVector(AsFloat(v1),f1); //warning 229: index tag mismatch (symbol "v1")
PrintToServer("f1 = %f %f %f",f1[0],f1[1],f1[2]);// f1 = 0.707106 0.707106 0.000000
}