SA-MP Forums Archive
ShowPlayerDialog - literal array/string passed to a non-const parameter - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: ShowPlayerDialog - literal array/string passed to a non-const parameter (/showthread.php?tid=663545)



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 
rowsfieldsadminname[24], str[92], message[1024], coloridadminlvl;
    
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(rows0adminname24);
        
cache_get_value_index_int(rows1adminlvl);
        
cache_get_value_index_int(rows2colorid);
        
format(strsizeof(str), "{%s}%s\t"white"%d\t%s\n"chatcolor[colorid], adminnameadminlvl, (Online(adminname)) ? (on) : (off));
        
strcat(messagestr);
    }
    
ShowPlayerDialog(playeridD_ADMINLISTDIALOG_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!