const char *prefix_name(int token)
{
unsigned int prefix = token-PREFIX_ENUM_START;
- if (prefix > elements(prefix_names))
+ if (prefix >= ARRAY_SIZE(prefix_names))
return NULL;
return prefix_names[prefix];
* This is a useful #define which I keep meaning to use more often:
* the number of elements of a statically defined array.
*/
-
-#define elements(x) ( sizeof(x) / sizeof(*(x)) )
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
/*
* List handling
}
/* lets walk thru aliases then */
- for (i = 0; i < elements(ofmt_aliases); i++) {
+ for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
if (ofmt_aliases[i].shortname &&
!nasm_stricmp(name, ofmt_aliases[i].shortname))
return ofmt_aliases[i].ofmt;
}
/* lets walk through aliases then */
- for (i = 0; i < elements(ofmt_aliases); i++) {
+ for (i = 0; i < ARRAY_SIZE(ofmt_aliases); i++) {
if (!ofmt_aliases[i].shortname)
continue;
fprintf(fp, " %-10s%s\n",
/* Binary search for the directive name */
i = -1;
- j = elements(tasm_directives);
+ j = ARRAY_SIZE(tasm_directives);
q = nasm_skip_word(p);
len = q - p;
if (len) {
static const int sizes[] =
{ 0, 1, 4, 16, 8, 10, 2, 32 };
- return sizes[bsii(str, size_names, elements(size_names))+1];
+ return sizes[bsii(str, size_names, ARRAY_SIZE(size_names))+1];
}
/*
return -1;
i = -1;
- j = elements(conditions);
+ j = ARRAY_SIZE(conditions);
while (j - i > 1) {
k = (j + i) / 2;
m = nasm_stricmp(t->text, conditions[k]);