Question about enum -
Kimble - 09.12.2015
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
Re: Question about enum -
SickAttack - 09.12.2015
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] =
{
{"", "", ""},
{"", "", ""},
{"", "", ""}
};
Re: Question about enum -
Kimble - 10.12.2015
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...
Re: Question about enum -
SickAttack - 10.12.2015
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);
Re: Question about enum -
dxhj - 10.12.2015
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 */
Re: Question about enum -
SickAttack - 10.12.2015
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.
Re: Question about enum -
dxhj - 10.12.2015
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
Re: Question about enum -
SickAttack - 10.12.2015
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.
Re: Question about enum -
dxhj - 10.12.2015
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.
Re: Question about enum -
Crayder - 10.12.2015
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)