Raised This Month: $51 Target: $400
 12% 

[SOLVED] Array sizes do not match, or destination array is too small


Post New Thread Reply   
 
Thread Tools Display Modes
shauli
Member
Join Date: Jun 2018
Old 01-30-2019 , 10:59   Re: [SOLVED] Array sizes do not match, or destination array is too small
Reply With Quote #11

Quote:
Originally Posted by ^SmileY View Post
I know that g_Stats[i][Objective] is same as g_Stats[i][4]
g_Stats[i][Objective] will be MAX_AUTHID_LENGTH+MAX_NAME_LENGTH+STATSX_MAX_ STATS+MAX_BODYHITS, something like 83 or so, not 4. So the compiler reads it as 83 + STATSX_MAX_OBJECTIVE instead of just STATSX_MAX_OBJECTIVE.
That's why you get an error.
It will also happen with get_players() or any function that expects a fixed size. I believe it is not your problem and that it should be fixed somehow in the new AMXX version.

Last edited by shauli; 01-30-2019 at 11:02.
shauli is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-30-2019 , 17:54   Re: [SOLVED] Array sizes do not match, or destination array is too small
Reply With Quote #12

Quote:
Originally Posted by ^SmileY View Post
get_stats2 have a fixed array for parameter. that is why im having troubles.

The solution is use as separated array, or just use a copy() to copy into the struct.
copy() only works on strings, not arrays. So it could work for ascii values (0-255), but if items 0, 1, or 2 are equal to 0, the data copy will end there. Not reliable for this purpose. Sadly, I don't think there is an array copy native.

Quote:
Originally Posted by shauli View Post
g_Stats[i][Objective] will be MAX_AUTHID_LENGTH+MAX_NAME_LENGTH+STATSX_MAX_ STATS+MAX_BODYHITS, something like 83 or so, not 4. So the compiler reads it as 83 + STATSX_MAX_OBJECTIVE instead of just STATSX_MAX_OBJECTIVE.
That's why you get an error.
It will also happen with get_players() or any function that expects a fixed size. I believe it is not your problem and that it should be fixed somehow in the new AMXX version.
No it doesn't, it will be sized at 4. Check for yourself : sizeof( g_Stats[][Objective] )

This should technically work, it just doesn't.
__________________
Bugsy is offline
shauli
Member
Join Date: Jun 2018
Old 01-31-2019 , 04:25   Re: [SOLVED] Array sizes do not match, or destination array is too small
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
No it doesn't, it will be sized at 4. Check for yourself : sizeof( g_Stats[][Objective] )

This should technically work, it just doesn't.
I was talking about the index, not the size.
g_Stats[i][4] will return the 5th char in Auth, g_Stats[i][83] (or something like that) will be Objective.
shauli is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-31-2019 , 17:44   Re: [SOLVED] Array sizes do not match, or destination array is too small
Reply With Quote #14

Correct, the elements of the enum sized array are packed side by side, so from that perspective yes. But the compiler should handle this scenario.
__________________
Bugsy is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-01-2019 , 05:21   Re: [SOLVED] Array sizes do not match, or destination array is too small
Reply With Quote #15

This actually still exists in SourcePawn as well, and Dvander says it's not an easy fix: https://github.com/alliedmodders/sourcepawn/issues/301
__________________
klippy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode