best practices doing non-static distance arrays c / c++?
if i have an array bound distance depending tangible used, i typically twin ways anxiety it.
array form 1: given bound distance formed define, i only interpretation loops referencing it.
#define maxplayers 4
int playerscores[maxplayers];
for(i=0;i<maxplayers;++i)
{
.... something any player
}
array form 2: given array grow equipment total it, i sizeof count array entries it. distance converted consistent compiler there shouldn't any runtime chastisement doing way.
typedef struct
{
fields....
}mystruct_def;
mystruct_def mystruct[]={
{entry 1},
{entry 2},
{entry 3...n}
};
for(i=0;i<(sizeof(mystruct)/sizeof(mystruct_def));++i)
{
..... something any entry
}
is there some-more glorious fortitude doing guess arrays but going past finish pause too early. thoughts? comments?
Comments
Post a Comment