sourcepawn icon indicating copy to clipboard operation
sourcepawn copied to clipboard

"Stock" hides unused variable warning

Open sirdigbot opened this issue 3 years ago • 2 comments

I'm not sure if this is a bug but it seems like one. The stock storage class specifier (are they called that in SP?) suppresses unused variable warnings on functions that are being used. public does too but I think that's intentional.

public void OnPluginStart()
{
    int x;
    int y;
    char z[32];

    Func1(x);
    Func2(x);
    Func3(x, y, z);
    Func4(x, y, z);
    
    FuncOther(x);
}


void Func1(int a) // warning 203: symbol is never used: "c"
{
    PrintToServer("side-effect");
    return;
}

stock void Func2(int a) // No warning
{
    PrintToServer("side-effect");
    return;
}


void Func3(int &a, int &b, char c[32]) // warning 203: symbol is never used: "c"
{
    PrintToServer("side-effect");
    return;
}

stock void Func4(int &a, int &b, char c[32]) // No warning
{
    PrintToServer("side-effect");
    return;
}


public void FuncOther(int a) // No warning (intentional?)
{
    PrintToServer("side-effect");
    return;
}

Side note, there's also no other way to make an array parameter optional (as in the function doesn't need to use the parameter, not that you don't need to pass the parameter), since unlike cell types you can't make it a reference to dismiss the warning.

sirdigbot avatar Mar 28 '22 02:03 sirdigbot

What compiler version is this with? stock has changed quite significantly in recent 1.11 versions. Skimming the Pawn language guide this does look intended, but we might want to change it anyway.

Side note, there's also no other way to make an array parameter optional (as in the function doesn't need to use the parameter, not that you don't need to pass the parameter)

#pragma unused c

asherkin avatar Mar 28 '22 08:03 asherkin

What compiler version is this with? stock has changed quite significantly in recent 1.11 versions. Skimming the Pawn language guide this does look intended, but we might want to change it anyway.

Tested on both version 1.10 (spider) and latest 1.11 (6863)

#pragma unused c

I'll be honest, I'm dumb for forgetting that literally minutes after somebody told me it in the discord. Specifically I forgot that I can't use that in my use case because I'm doing gross stuff with macros to create functions.

sirdigbot avatar Mar 28 '22 08:03 sirdigbot