Use ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) to improve code readability.
Defined it in appropriate header file.
Signed-off-by: Simran Singhal <singhalsimran0@gmail.com>
uint32_t str_to_ceph_entity_type(const char * str)
{
size_t i;
- for (i = 0; i < sizeof(STR_TO_ENTITY_TYPE)/sizeof(STR_TO_ENTITY_TYPE[0]); ++i) {
+ for (i = 0; i < ARRAY_SIZE(STR_TO_ENTITY_TYPE); ++i) {
if (strcmp(str, STR_TO_ENTITY_TYPE[i].str) == 0)
return STR_TO_ENTITY_TYPE[i].type;
}
#include "msg/msg_types.h"
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
+
/* Represents a Ceph entity name.
*
* For example, mds.0 is the name of the first metadata server.
0x0000007ful, 0x000007fful, 0x0000fffful,
0x001ffffful, 0x03fffffful, 0x7ffffffful
};
- static const int MAX_VAL_SZ = sizeof(max_val) / sizeof(max_val[0]);
+ static const int MAX_VAL_SZ = ARRAY_SIZE(max_val);
for (i = 0; i < MAX_VAL_SZ; ++i) {
if (u <= max_val[i])
#define MAX_UTF8_SZ 6
#define INVALID_UTF8_CHAR 0xfffffffful
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
#ifdef __cplusplus
extern "C" {