ShowPlayerDialog - literal array/string passed to a non-const parameter -
kaZax - 04.02.2019
Hi!
I update zeex compiler to 3.10.9.
And get warning "warning 239: literal array/string passed to a non-const parameter" on ShowPlayerDialog.
PHP код:
public: AdminList(playerid)
{
new rows, fields, adminname[24], str[92], message[1024], colorid, adminlvl;
strcat(message, ""white"Nickname\t"white"Level\t"white"Status\n");
cache_get_row_count(rows);
cache_get_field_count(fields);
while(rows--)
{
cache_get_value_index(rows, 0, adminname, 24);
cache_get_value_index_int(rows, 1, adminlvl);
cache_get_value_index_int(rows, 2, colorid);
format(str, sizeof(str), "{%s}%s\t"white"%d\t%s\n", chatcolor[colorid], adminname, adminlvl, (Online(adminname)) ? (on) : (off));
strcat(message, str);
}
ShowPlayerDialog(playerid, D_ADMINLIST, DIALOG_STYLE_TABLIST_HEADERS, ""q"Администраторы", message, "Ok", "");
return 1;
}
How to fix it?
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
Calisthenics - 04.02.2019
Open a_samp.inc and replace:
pawn Код:
native ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[]);
with:
pawn Код:
native ShowPlayerDialog(playerid, dialogid, style, const caption[], const info[], const button1[], const button2[]);
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
kaZax - 04.02.2019
Quote:
Originally Posted by Calisthenics
Open a_samp.inc and replace:
pawn Код:
native ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[]);
with:
pawn Код:
native ShowPlayerDialog(playerid, dialogid, style, const caption[], const info[], const button1[], const button2[]);
|
did not help. same warnings
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
Calisthenics - 04.02.2019
I reverted back and tested compiler 3.10.9 but it did not give me this error for `ShowPlayerDialog` function. Here is my test:
pawn Код:
#include <a_samp>
#define D_ADMINLIST 5
#define q "{FFFFFF}"
main()
{
const playerid = 0;
new message[] = "Nickname\tLevel\tStatus\n";
ShowPlayerDialog(playerid, D_ADMINLIST, DIALOG_STYLE_TABLIST_HEADERS, ""q"??????????????", message, "Ok", "");
}
Can you open a new file and try to compile it? If it compiles without warnings/errors, then the problem lies somewhere else.
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
SymonClash - 04.02.2019
Or just use compiler version 3.10.8 that hides this useless warnings.
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
kaZax - 04.02.2019
Quote:
Originally Posted by Calisthenics
I reverted back and tested compiler 3.10.9 but it did not give me this error for `ShowPlayerDialog` function. Here is my test:
pawn Код:
#include <a_samp>
#define D_ADMINLIST 5 #define q "{FFFFFF}"
main() { const playerid = 0; new message[] = "Nickname\tLevel\tStatus\n"; ShowPlayerDialog(playerid, D_ADMINLIST, DIALOG_STYLE_TABLIST_HEADERS, ""q"??????????????", message, "Ok", ""); }
Can you open a new file and try to compile it? If it compiles without warnings/errors, then the problem lies somewhere else.
|
yes, compiled without warnings.
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
khRamin78 - 18.02.2019
Quote:
Originally Posted by SymonClash
Or just use compiler version 3.10.8 that hides this useless warnings.
|
these errors are not useless ! if you think its useless then you are not a programmer you are just a copy paste machine
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
SymonClash - 18.02.2019
Quote:
Originally Posted by khRamin78
these errors are not useless ! if you think its useless then you are not a programmer you are just a copy paste machine
|
Do you think how much time does it takes to rewrite a 20k lines gamemode just to add this "static const" to all variables? And what about fuck them?
I don't see the utility of it, probably i'm too ignorant but we lived too even without this errors.
Download Zeex's 3.10.9, open a large gamemode (15-20k lines), then good luck in fixing all this errors, even in native includes.
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
kristo - 18.02.2019
Quote:
Originally Posted by SymonClash
I don't see the utility of it, probably i'm too ignorant but we lived too even without this errors.
|
3.10.9 fixes an
issue with the compiler where array literals could be modified, which is a thing that should definitely not be able to be done. The checks for detecting attempts to modify array literals do not need to be ran for constant arrays, speeding up the process, and in the discussion it was widely accepted that non-const correct code is bad code in general, therefore this feature was implemented.
Here is some documentation on const correctness (yes, these are two different links):
https://github.com/pawn-lang/compile...st-Correctness
https://github.com/pawn-lang/compile...st-correctness
Quote:
Originally Posted by SymonClash
good luck in fixing all this errors, even in native includes.
|
Const-correct versions of the default includes are available here:
https://github.com/sampctl/pawn-stdlib
https://github.com/sampctl/samp-stdlib
Most actively maintained libraries are also const-corrected by now, including the 5.x branch of YSI.
Re: ShowPlayerDialog - literal array/string passed to a non-const parameter -
Pottus - 18.02.2019
Quote:
Originally Posted by SymonClash
Do you think how much time does it takes to rewrite a 20k lines gamemode just to add this "static const" to all variables? And what about fuck them?
I don't see the utility of it, probably i'm too ignorant but we lived too even without this errors.
Download Zeex's 3.10.9, open a large gamemode (15-20k lines), then good luck in fixing all this errors, even in native includes.
|
15-20K lines is a small gamemode just a baby!