30 Sep, 2007, Zeno wrote in the 1st comment:
Votes: 0
No idea why I'm getting this error. I copied this line from build.c
for ( x = 0; x < (sizeof(o_flags) / sizeof(o_flags[0])); x++ )


To act_wiz.c and it's getting that error. I know o_flags is extern'd in mud.h:
extern  char *  const   o_flags         [];


So act_wiz.c should know what it is. Any ideas?
30 Sep, 2007, David Haley wrote in the 2nd comment:
Votes: 0
It doesn't know the size of the o_flags array, because its extern definition doesn't specify the size, and therefore sizeof can't tell you what the size is.
30 Sep, 2007, Zeno wrote in the 3rd comment:
Votes: 0
Ah okay. Hm, what would you recommend?
30 Sep, 2007, Caius wrote in the 4th comment:
Votes: 0
I usually make a function like this in the same file where the o_flags array is defined:
size_t o_flags_size()
{
return sizeof( o_flags ) / sizeof( o_flags[0] );
}

then call that instead like so:
for ( x = 0; x < o_flags_size(); x++ )
30 Sep, 2007, David Haley wrote in the 5th comment:
Votes: 0
Zeno said:
Ah okay. Hm, what would you recommend?

You need to have the array declared with its size in the same "file" (source + relevant includes) for sizeof to give you the size of the block of memory used for that array. Either that, or use constants or something to keep track of the flags array size.

Caius's suggestion is a good way to have a function that will give you the size of the array, so that you can leave that function in the file where the array's size is defined, and still be able to access that size information from files in which you cannot specify the array's size. (Multiple definitions and all that.)
0.0/5