*
* Known contributors to this file:
* Doug Hay, 1998
- * Markus Armbruster, 2004-2014
+ * Markus Armbruster, 2004-2020
*/
#ifndef MISC_H
#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 */
* cargo.c: Cargo lists
*
* Known contributors to this file:
- * Markus Armbruster, 2009
+ * Markus Armbruster, 2009-2020
*/
#include <config.h>
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;
}
* filetable.c: Empire game data file descriptions.
*
* Known contributors to this file:
- * Markus Armbruster, 2005-2016
+ * Markus Armbruster, 2005-2020
*/
#include <config.h>
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) \
*/
#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.
*/
#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)
* nsc.c: Empire selection global structures
*
* Known contributors to this file:
- * Markus Armbruster, 2004-2016
+ * Markus Armbruster, 2004-2020
*/
/*
#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[] = {
* Dave Pare, 1986
* Thomas Ruschak, 1992
* Steve McClure, 1996
- * Markus Armbruster, 2006-2014
+ * Markus Armbruster, 2006-2020
*/
#include <config.h>
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)
*
* Known contributors to this file:
* Ron Koenderink, 2005
- * Markus Armbruster, 2005-2016
+ * Markus Armbruster, 2005-2020
*/
#include <config.h>
{
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;
* paths.c: Routines associated with paths, directions, etc.
*
* Known contributors to this file:
- * Markus Armbruster, 2005-2011
+ * Markus Armbruster, 2005-2020
*/
#include <config.h>
{
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];
* Jeff Bailey, 1990
* Steve McClure, 1996
* Ron Koenderink, 2005-2009
- * Markus Armbruster, 2006-2017
+ * Markus Armbruster, 2006-2020
*/
#include <config.h>
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
*
* Known contributors to this file:
* Dave Pare, 1989
- * Markus Armbruster, 2009-2011
+ * Markus Armbruster, 2009-2020
*/
#include <config.h>
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;
*
* Known contributors to this file:
* Dave Pare, 1989
- * Markus Armbruster, 2006-2011
+ * Markus Armbruster, 2006-2020
*/
#include <config.h>
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;
* Dave Pare, 1994
* Steve McClure, 1996
* Ron Koenderink, 2005
- * Markus Armbruster, 2007-2012
+ * Markus Armbruster, 2007-2020
*/
#include <config.h>
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);