Hi,
I am trying to compile this piece of code found below.
However, I got an error saying "Initialization value must be constant expression."on every line of iteminfo_fields, weaponinfo_fields and projectileinfo_fields definitions, except at the last line of each "{NULL, 0, 0}"
I am guessing it is from ITEMINFO_OFS(), WEAPON_OFS(), PROJECTILE_OFS().
I am trying to understand these three lines:
#define WEAPON_OFS(x) (size_t)&(((weaponinfo_t *)0)->x)
#define PROJECTILE_OFS(x) (size_t)&(((projectileinfo_t *)0)->x)
#define ITEMINFO_OFS(x) (size_t)&(((iteminfo_t *)0)->x)
But, I really cannot understand how they work...???
I need help dissecting them. Can anyone read them and rewrite them in a simpler form?
#define WEAPON_OFS(x) (size_t)&(((weaponinfo_t *)0)->x)
#define PROJECTILE_OFS(x) (size_t)&(((projectileinfo_t *)0)->x)
#define ITEMINFO_OFS(x) (size_t)&(((iteminfo_t *)0)->x)
fielddef_t iteminfo_fields[] =
{
{"name", ITEMINFO_OFS(name), FT_STRING},
{"model", ITEMINFO_OFS(model), FT_STRING},
{"modelindex", ITEMINFO_OFS(modelindex), FT_INT},
{"type", ITEMINFO_OFS(type), FT_INT},
{"index", ITEMINFO_OFS(index), FT_INT},
{"respawntime", ITEMINFO_OFS(respawntime), FT_FLOAT},
{"mins", ITEMINFO_OFS(mins), FT_FLOAT|FT_ARRAY, 3},
{"maxs", ITEMINFO_OFS(maxs), FT_FLOAT|FT_ARRAY, 3},
{NULL, 0, 0}
};
static fielddef_t weaponinfo_fields[] =
{
{"number", WEAPON_OFS(number), FT_INT},
{"name", WEAPON_OFS(name),FT_STRING},
{"level", WEAPON_OFS(level), FT_INT},
{"model", WEAPON_OFS(model), T_STRING},
{"weaponindex", WEAPON_OFS(weaponindex), FT_INT},
{"flags", WEAPON_OFS(flags), FT_INT},
{"projectile", WEAPON_OFS(projectile), FT_STRING},
{"numprojectiles", WEAPON_OFS(numprojectiles), FT_INT},
{"hspread", WEAPON_OFS(hspread), FT_FLOAT},
{"vspread", WEAPON_OFS(vspread), FT_FLOAT},
{"speed", WEAPON_OFS(speed), FT_FLOAT},
{"acceleration", WEAPON_OFS(acceleration), FT_FLOAT},
{"recoil", WEAPON_OFS(recoil), FT_FLOAT|FT_ARRAY, 3},
{"offset", WEAPON_OFS(offset), FT_FLOAT|FT_ARRAY, 3},
{"angleoffset", WEAPON_OFS(angleoffset), FT_FLOAT|FT_ARRAY, 3},
{"extrazvelocity", WEAPON_OFS(extrazvelocity), FT_FLOAT},
{"ammoamount", WEAPON_OFS(ammoamount), FT_INT},
{"ammoindex", WEAPON_OFS(ammoindex), FT_INT},
{"activate", WEAPON_OFS(activate), FT_FLOAT},
{"reload", WEAPON_OFS(reload), FT_FLOAT},
{"spinup", WEAPON_OFS(spinup), FT_FLOAT},
{"spindown", WEAPON_OFS(spindown), FT_FLOAT},
{NULL, 0, 0, 0}
};
static fielddef_t projectileinfo_fields[] =
{
{"name", PROJECTILE_OFS(name), FT_STRING},
{"model", WEAPON_OFS(model), FT_STRING},
{"flags", PROJECTILE_OFS(flags), FT_INT},
{"gravity", PROJECTILE_OFS(gravity), FT_FLOAT},
{"damage", PROJECTILE_OFS(damage), FT_INT},
{"radius", PROJECTILE_OFS(radius), FT_FLOAT},
{"visdamage", PROJECTILE_OFS(visdamage), FT_INT},
{"damagetype", PROJECTILE_OFS(damagetype), FT_INT},
{"healthinc", PROJECTILE_OFS(healthinc), FT_INT},
{"push", PROJECTILE_OFS(push), FT_FLOAT},
{"detonation", PROJECTILE_OFS(detonation), FT_FLOAT},
{"bounce", PROJECTILE_OFS(bounce), FT_FLOAT},
{"bouncefric", PROJECTILE_OFS(bouncefric), FT_FLOAT},
{"bouncestop", PROJECTILE_OFS(bouncestop), FT_FLOAT},
{NULL, 0, 0, 0}
};
Note:
My situation is a bit complicated at the moment. However,
I do not know the name of the compiler. The environment is Linux tho.
It is not my code, but I need to have it compile.