SA-MP Forums Archive
Size of structure? - 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: Size of structure? (/showthread.php?tid=319911)



Size of structure? - Programie - 20.02.2012

Hi,

my next problem.

How can I get the size of a structure (Defined with enum)?

Код:
enum myStructure
{
	StructureItem1,
	StructureItem2,
	StructureItem3
}
Using sizeof(myStructure) shows me a "Constant symbol has no size" error.


Re: Size of structure? - chrism11 - 20.02.2012

i don't believe you can get the size of a enum lol

try

Код:
new myStructure[3] =
{
	StructureItem1,
	StructureItem2,
	StructureItem3
};
if thats not what your talking please show the code where your getting the error so i can understand what your trying to do


Re: Size of structure? - Programie - 20.02.2012

Quote:
Originally Posted by chrism11
Посмотреть сообщение
i don't believe you can get the size of a enum lol

try

Код:
new myStructure[3] =
{
	StructureItem1,
	StructureItem2,
	StructureItem3
};
if thats not what your talking please show the code where your getting the error so i can understand what your trying to do
No, I want to get the number of constants in the enum. In my example there are 3 constants, so sizeof should return 3.


My structure and array using it:
Код:
enum enum_permission
{
	PERMISSION_ADMIN,
	PERMISSION_MAPPER,
	PERMISSION_MODERATOR,
	PERMISSION_NPCADMIN,
	PERMISSION_SERVERADMIN,
	PERMISSION_TELEPORT
}

new permissions[MAX_PLAYERS][enum_permission];
And later I want to loop through the structure items:
Код:
for (new permission = 0; permission < 6; permission++)// TODO: Replace constant number (6) with anything to get size of enum_permission
{
	if (permissions[playerid][enum_permission:permission])
	{
		if (strlen(string))
		{
			format(string, sizeof(string), "%s ", string);
		}
		format(string, sizeof(string), "%s%s", string, GetPermissionName(permission));
	}
}
Is there really no way to get the size of the structure?


Re: Size of structure? - Vince - 20.02.2012

pawn Код:
sizeof(permissions[])
Should do the trick.


Re: Size of structure? - Programie - 20.02.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
pawn Код:
sizeof(permissions[])
Should do the trick.
Would that not get the size of the array? Mhh I will test it.

//EDIT: Seems to work. It returns 6.

Thanks