alliedmodders / sourcepawn

A small, statically typed scripting language.
Other
363 stars 62 forks source link

Compiler error 035 #960

Closed A1mDev closed 3 months ago

A1mDev commented 6 months ago

https://steamuserimages-a.akamaihd.net/ugc/2470858270604655082/FC99F271EF3D23E613F30E17C1792BA7D5E95E64/

I don't know if this should be the case, now the compiler complains about passing a const char[] parameter instead of char[]

Test code:

static const char sSurvivorsNames[][] = {"Nick", "Rochelle", "Coach", "Ellis"};
static int iActor;

public void OnPluginStart()
{
    Foo(sSurvivorsNames[iActor++]);
}

void Foo(char[] sArg = "")
{
    PrintToServer(sArg);
}
dvander commented 6 months ago

hrm... seems like working as-is? const is transitive, and you're discarding const by passing to Foo().

A1mDev commented 6 months ago

I just passed this const char[] to the sourcemod function, I can’t fix the built-in functions in the sourcemod, that’s why this question arose.

static const char sSurvivorsNames[][] = {"Nick", "Rochelle", "Coach", "Ellis"};

public void OnPluginStart()
{
    //CheatCommand(int client, char[] command, char[] arguments = "")
    CheatCommand(0, "sb_add", sSurvivorsNames[0])
}
dvander commented 6 months ago

Is CheatCommand a SourceMod function? If so, let's move this bug there and fix it there.

A1mDev commented 6 months ago

Oops, I was wrong about this function, but I think we can find another function without the const keyword.

A1mDev commented 6 months ago

I still have a question, why it is impossible to declare a constant in the global scope without keywords public, stock, static. Example:

// public const char sSurvivorsNames[][] = {"Nick", "Rochelle", "Coach", "Ellis"};
// static const char sSurvivorsNames[][] = {"Nick", "Rochelle", "Coach", "Ellis"};
// stock const char sSurvivorsNames[][] = {"Nick", "Rochelle", "Coach", "Ellis"};

const char sSurvivorsNames[][] = {"Nick", "Rochelle", "Coach", "Ellis"};

public void OnPluginStart()  {}

image

dvander commented 6 months ago

Hate is a strong word, and thus, the perfect word to describe my feelings toward "const". If I had a do-over I'd have removed it from SourcePawn on day 1.

Anyway, the reason it's not possible is just a quirk in the parser. It'd be pretty easy to fix, but... what's the point? const isn't helping you anywhere.