Size of structure?
#1

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.
Reply
#2

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
Reply
#3

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?
Reply
#4

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)