New macro ARRAY_SIZE()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
50d84c025b
commit
5e45859979
11 changed files with 37 additions and 35 deletions
|
@ -29,7 +29,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Doug Hay, 1998
|
||||
* Markus Armbruster, 2004-2014
|
||||
* Markus Armbruster, 2004-2020
|
||||
*/
|
||||
|
||||
#ifndef MISC_H
|
||||
|
@ -89,6 +89,11 @@ extern void (*oops_handler)(void);
|
|||
#define BUILD_ASSERT(cond) \
|
||||
((void)BUILD_ASSERT_ONE(cond))
|
||||
|
||||
/*
|
||||
* Number of elements in ARRAY.
|
||||
*/
|
||||
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
|
||||
|
||||
void exit_nomem(void) ATTRIBUTE((noreturn));
|
||||
|
||||
/* return codes from command routines */
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* cargo.c: Cargo lists
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Markus Armbruster, 2009
|
||||
* Markus Armbruster, 2009-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -94,7 +94,7 @@ clink_init(struct clink *cl)
|
|||
unsigned i;
|
||||
|
||||
cl->next = -1;
|
||||
for (i = 0; i < sizeof(cl->head) / sizeof(*cl->head); i++)
|
||||
for (i = 0; i < ARRAY_SIZE(cl->head); i++)
|
||||
cl->head[i] = -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* filetable.c: Empire game data file descriptions.
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Markus Armbruster, 2005-2016
|
||||
* Markus Armbruster, 2005-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -70,9 +70,6 @@ static void nchr_oninit(void *);
|
|||
|
||||
static char dummy_cache;
|
||||
|
||||
/* Number of elements in ARRAY. */
|
||||
#define SZ(array) (sizeof(array) / sizeof((array)[0]))
|
||||
|
||||
/* Initializers for members flags... */
|
||||
/* Unmapped cache */
|
||||
#define UNMAPPED_CACHE(type, nent, flags) \
|
||||
|
@ -84,7 +81,7 @@ static char dummy_cache;
|
|||
*/
|
||||
#define ARRAY_CACHE(array, flags) \
|
||||
sizeof(*(array)), -1, (flags), (char *)(array), \
|
||||
SZ((array)), 0, 0, 0, -1
|
||||
ARRAY_SIZE((array)), 0, 0, 0, -1
|
||||
/*
|
||||
* Mapped cache, array with unknown size.
|
||||
* Member csize gets a bogus value, needs to be fixed up.
|
||||
|
@ -98,7 +95,7 @@ static char dummy_cache;
|
|||
*/
|
||||
#define ARRAY_TABLE(array, nent, flags) \
|
||||
sizeof(*(array)), (nent), (flags), (char *)(array), \
|
||||
SZ((array)), 0, (nent), (nent), -1
|
||||
ARRAY_SIZE((array)), 0, (nent), (nent), -1
|
||||
|
||||
/* Common configuration table flags */
|
||||
#define EFF_CFG (EFF_PRIVATE | EFF_MEM | EFF_STATIC | EFF_SENTINEL)
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* nsc.c: Empire selection global structures
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Markus Armbruster, 2004-2016
|
||||
* Markus Armbruster, 2004-2020
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -640,7 +640,7 @@ struct castr cou_ca[] = {
|
|||
#undef CURSTR
|
||||
};
|
||||
|
||||
struct castr nat_ca[sizeof(cou_ca) / sizeof(*cou_ca)];
|
||||
struct castr nat_ca[ARRAY_SIZE(cou_ca)];
|
||||
/* initialized by nsc_init() */
|
||||
|
||||
struct castr relat_ca[] = {
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* Dave Pare, 1986
|
||||
* Thomas Ruschak, 1992
|
||||
* Steve McClure, 1996
|
||||
* Markus Armbruster, 2006-2014
|
||||
* Markus Armbruster, 2006-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -716,7 +716,7 @@ ac_flak_dam(int guns, int def, int pl_flags)
|
|||
0.35f, 0.40f, 0.45f, 0.50f, 0.50f, 0.55f, 0.60f, 0.65f,
|
||||
/* +5 +6 +7 +8 >+8 */
|
||||
0.70f,0.75f, 0.80f, 0.85f, 1.1305f };
|
||||
enum { FLAK_MAX = sizeof(flaktable)/sizeof(flaktable[0]) - 1 };
|
||||
enum { FLAK_MAX = ARRAY_SIZE(flaktable) - 1 };
|
||||
|
||||
flak = guns - def;
|
||||
if ((pl_flags & P_T) == 0)
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Ron Koenderink, 2005
|
||||
* Markus Armbruster, 2005-2016
|
||||
* Markus Armbruster, 2005-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -63,7 +63,7 @@ ef_init_srv(int force_bad_state)
|
|||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < sizeof(fileinit) / sizeof(fileinit[0]); i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(fileinit); i++) {
|
||||
empfile[fileinit[i].ef_type].postread = fileinit[i].postread;
|
||||
empfile[fileinit[i].ef_type].prewrite = fileinit[i].prewrite;
|
||||
empfile[fileinit[i].ef_type].onresize = fileinit[i].onresize;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* paths.c: Routines associated with paths, directions, etc.
|
||||
*
|
||||
* Known contributors to this file:
|
||||
* Markus Armbruster, 2005-2011
|
||||
* Markus Armbruster, 2005-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -73,7 +73,7 @@ diridx(char dir)
|
|||
{
|
||||
unsigned i = dir - 'a';
|
||||
|
||||
if (CANT_HAPPEN(i >= sizeof(dirindex) / sizeof(*dirindex)
|
||||
if (CANT_HAPPEN(i >= ARRAY_SIZE(dirindex)
|
||||
|| dirindex[i] < 0))
|
||||
return DIR_STOP;
|
||||
return dirindex[i];
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* Jeff Bailey, 1990
|
||||
* Steve McClure, 1996
|
||||
* Ron Koenderink, 2005-2009
|
||||
* Markus Armbruster, 2006-2017
|
||||
* Markus Armbruster, 2006-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -187,7 +187,7 @@ show_nuke_stats(int tlev)
|
|||
void
|
||||
show_nuke_build(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(nchr) / sizeof(*nchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(nchr)];
|
||||
int n = make_nchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct nchrstr *np;
|
||||
|
@ -208,7 +208,7 @@ show_nuke_build(int tlev)
|
|||
void
|
||||
show_nuke_capab(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(nchr) / sizeof(*nchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(nchr)];
|
||||
int n = make_nchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct nchrstr *np;
|
||||
|
@ -230,7 +230,7 @@ show_nuke_capab(int tlev)
|
|||
void
|
||||
show_ship_build(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(mchr) / sizeof(*mchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(mchr)];
|
||||
int n = make_mchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct mchrstr *mp;
|
||||
|
@ -247,7 +247,7 @@ show_ship_build(int tlev)
|
|||
void
|
||||
show_ship_stats(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(mchr) / sizeof(*mchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(mchr)];
|
||||
int n = make_mchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct mchrstr *mp;
|
||||
|
@ -268,7 +268,7 @@ show_ship_stats(int tlev)
|
|||
void
|
||||
show_ship_capab(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(mchr) / sizeof(*mchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(mchr)];
|
||||
int n = make_mchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct mchrstr *mp;
|
||||
|
@ -286,7 +286,7 @@ show_ship_capab(int tlev)
|
|||
void
|
||||
show_plane_stats(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(plchr) / sizeof(*plchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(plchr)];
|
||||
int n = make_plchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct plchrstr *pp;
|
||||
|
@ -304,7 +304,7 @@ show_plane_stats(int tlev)
|
|||
void
|
||||
show_plane_capab(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(plchr) / sizeof(*plchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(plchr)];
|
||||
int n = make_plchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct plchrstr *pp;
|
||||
|
@ -321,7 +321,7 @@ show_plane_capab(int tlev)
|
|||
void
|
||||
show_plane_build(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(plchr) / sizeof(*plchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(plchr)];
|
||||
int n = make_plchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct plchrstr *pp;
|
||||
|
@ -339,7 +339,7 @@ show_plane_build(int tlev)
|
|||
void
|
||||
show_land_build(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(lchr) / sizeof(*lchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(lchr)];
|
||||
int n = make_lchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct lchrstr *lp;
|
||||
|
@ -358,7 +358,7 @@ show_land_build(int tlev)
|
|||
void
|
||||
show_land_capab(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(lchr) / sizeof(*lchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(lchr)];
|
||||
int n = make_lchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct lchrstr *lcp;
|
||||
|
@ -376,7 +376,7 @@ show_land_capab(int tlev)
|
|||
void
|
||||
show_land_stats(int tlev)
|
||||
{
|
||||
struct chr_index chridx[sizeof(lchr) / sizeof(*lchr)];
|
||||
struct chr_index chridx[ARRAY_SIZE(lchr)];
|
||||
int n = make_lchr_index(chridx, tlev);
|
||||
int i;
|
||||
struct lchrstr *lcp;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Dave Pare, 1989
|
||||
* Markus Armbruster, 2009-2011
|
||||
* Markus Armbruster, 2009-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -241,7 +241,7 @@ snxtitem_use_condarg(struct nstr_item *np)
|
|||
|
||||
if (!player->condarg)
|
||||
return 1;
|
||||
n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond),
|
||||
n = nstr_comp(np->cond, ARRAY_SIZE(np->cond),
|
||||
np->type, player->condarg);
|
||||
if (n < 0)
|
||||
return 0;
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*
|
||||
* Known contributors to this file:
|
||||
* Dave Pare, 1989
|
||||
* Markus Armbruster, 2006-2011
|
||||
* Markus Armbruster, 2006-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -127,7 +127,7 @@ snxtsct_use_condarg(struct nstr_sect *np)
|
|||
|
||||
if (!player->condarg)
|
||||
return 1;
|
||||
n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond),
|
||||
n = nstr_comp(np->cond, ARRAY_SIZE(np->cond),
|
||||
EF_SECTOR, player->condarg);
|
||||
if (n < 0)
|
||||
return 0;
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
* Dave Pare, 1994
|
||||
* Steve McClure, 1996
|
||||
* Ron Koenderink, 2005
|
||||
* Markus Armbruster, 2007-2012
|
||||
* Markus Armbruster, 2007-2020
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -83,7 +83,7 @@ static int
|
|||
update_get_schedule(void)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
int n = sizeof(update_time) / sizeof(*update_time);
|
||||
int n = ARRAY_SIZE(update_time);
|
||||
int i;
|
||||
|
||||
ef_truncate(EF_UPDATES, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue