Question about enum
#1

Questions in comments:

Код:
enum someEnum
{
    var1,
    var2,
    var3,
    var4,
    var5,  // On the last variable here does it matter if there's a coma or not? I like to put it cause it looks neat?
}; // Is the semicolon necessary here?
Thanks
Reply
#2

The script complies with or without both (on the enumerator), where it is required is on arrays.

pawn Код:
enum eArray
{
    list_element_1[144],
    list_element_2[144],
    list_element_3[144],
}

static const aArray[][eArray] =
{
    {"", "", ""},
    {"", "", ""},
    {"", "", ""}
};
Reply
#3

Awesome, one more question, is there a way to get the size of an element inside of an enumerator?
Like how would i find out that list_element_2 is 144 long?

I tried using sizeof() in different ways but keep getting errors...
Reply
#4

Quote:
Originally Posted by Kimble
Посмотреть сообщение
Awesome, one more question, is there a way to get the size of an element inside of an enumerator?
Like how would i find out that list_element_2 is 144 long?

I tried using sizeof() in different ways but keep getting errors...
The only way (that lets you to easily edit the destination size of a list element) that I can think of is:

pawn Код:
enum eArray
{
    list_element_1[144],
    list_element_1_so,
    list_element_2[144],
    list_element_2_so,
    list_element_3[144],
    list_element_3_so
};

static const aArray[][eArray] =
{
    {"", 144, "", 144, "", 144},
    {"", 144, "", 144, "", 144},
    {"", 144, "", 144, "", 144}
};

main()
{
    printf("%d", aArray[0][list_element_3_so]);
}
Or just input the size of a list element in to a function manually (when it is needed).

pawn Код:
strcat(aArray[0][list_element_3], "test", 144);
Reply
#5

No, it doesn't matter. The compiler will accept with the last coma or not.

Of course, here's an example:

Код:
	
enum myEnum {
	foo[144]
}
	
new bar[myEnum];
sizeof(bar[foo]); /* 144 */
Reply
#6

Quote:
Originally Posted by dxhj
Посмотреть сообщение
No, it doesn't matter. The compiler will accept with the last coma or not.

Of course, here's an example:

Код:
	
enum myEnum {
	foo[144]
}
	
new bar[myEnum];
sizeof(bar[foo]); /* 144 */
That doesn't apply to tridimensional arrays.
Reply
#7

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
That doesn't apply to tridimensional arrays.
Код:
	
enum myEnum {
	foo[144]
}

new bar[5][myEnum];
sizeof(bar[]); // 144
Now, it does.


@EDIT

Sorry. I read bidimensional (almost sleeping haha). Anyway, the only change will be one [] more:
Код:
new bar[5][4][myEnum];
sizeof(bar[][]); // 144
Reply
#8

Quote:
Originally Posted by dxhj
Посмотреть сообщение
Код:
	
enum myEnum {
	foo[144]
}

new bar[5][myEnum];
sizeof(bar[]); // 144
Now, it does.


@EDIT

Sorry. I read bidimensional (almost sleeping haha). Anyway, the only change will be one [] more:
Код:
new bar[5][4][myEnum];
sizeof(bar[][]); // 144
1st:

pawn Код:
enum myEnum
{
    foo[144],
    fooo[256],
    foooo[120]
}

new bar[5][myEnum];
printf("%d", sizeof(bar[])); // 520
2nd:

pawn Код:
enum myEnum
{
    foo[144],
    fooo[256],
    foooo[120]
}

new bar[5][myEnum];
printf("%d", sizeof(bar[][])); // 1
pawn Код:
enum myEnum
{
    foo[144],
    fooo[5],
    foooo[5]
}

new bar[5][4][myEnum];
printf("%d", sizeof(bar[][])); // 154
We are trying to get the size of a single list element, not the size of each and every list elements in a enumerator.
Reply
#9

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
1st:

pawn Код:
enum myEnum
{
    foo[144],
    fooo[256],
    foooo[120]
}

new bar[5][myEnum];
printf("%d", sizeof(bar[])); // 520
2nd:

pawn Код:
enum myEnum
{
    foo[144],
    fooo[256],
    foooo[120]
}

new bar[5][myEnum];
printf("%d", sizeof(bar[][])); // 1
pawn Код:
enum myEnum
{
    foo[144],
    fooo[5],
    foooo[5]
}

new bar[5][4][myEnum];
printf("%d", sizeof(bar[][])); // 154
We are trying to get the size of a single list element, not the size of each and every list elements in a enumerator.
It can't be done. Use arrays.
Reply
#10

I'm just going to point out that enumerators can be used as tags...

Think of it like this (no this won't work, just an example):

pawn Код:
sizeof(eArray:list_element_2)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)