#include <amxmodx>
enum _:CATEGORIES_ENUM {
CATEGORY__FREE,
CATEGORY__VIP,
CATEGORY__PREMIUM,
CATEGORY__GIRL,
CATEGORY__HOLIDAY,
CATEGORY__END
}
#define INVALID_CATEGORY_POS -1
new g_iFirstPos[CATEGORIES_ENUM] = { INVALID_CATEGORY_POS, ... }
new g_iFirstPos2[ 5 ] = { INVALID_CATEGORY_POS, ... }
public plugin_init() {
for(new i; i < CATEGORIES_ENUM; i++) {
log_to_file("ArrayDebug.log", "g_iFirstPos[%i]: %i", i, g_iFirstPos[i])
}
for(new i; i < CATEGORIES_ENUM; i++) {
log_to_file("ArrayDebug.log", "g_iFirstPos2[%i]: %i", i, g_iFirstPos2[i])
}
}
Compiled, then decompiled:
new g_iFirstPos[5] =
{
-1, 0, 0, 0, 0
};
new g_iFirstPos2[5] =
{
-1, ...
};
public plugin_init()
{
new i;
while (i < 5)
{
log_to_file("ArrayDebug.log", "g_iFirstPos[%i]: %i", i, g_iFirstPos[i]);
i++;
}
new i;
while (i < 5)
{
log_to_file("ArrayDebug.log", "g_iFirstPos2[%i]: %i", i, g_iFirstPos2[i]);
i++;
}
return 0;
}
As you can see, only first cell of g_iFirstPos was set to -1
Bug exists only if CATEGORIES_ENUM is used as a size for g_iFirstPos
If i replace CATEGORIES_ENUM to 5 all is ok (all cells got -1)
If i use below construction, all is also ok
There are a lot of bugs with enums, you must use const Variable = CATEGORY__END; to pretend beeing a constant variable, we need to update a pawn core as well to fix them, in some cases it is breakable.
Problematic code:
Compiled, then decompiled:
As you can see, only first cell of g_iFirstPos was set to -1 Bug exists only if CATEGORIES_ENUM is used as a size for g_iFirstPos If i replace CATEGORIES_ENUM to 5 all is ok (all cells got -1) If i use below construction, all is also ok