From e6908177eccfacb8285f916beec706f652d4ac1f Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 9 Apr 2013 16:16:34 +0000 Subject: Add static/const keywords to the arrays. This theoretically allows a compiler to optimize (parts of) the array away if unused. While there, make the array size implicit and use a _Static_assert() to ensure that the definition matches up with the number of elements in the list. --- include/protocols/timed.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/protocols') diff --git a/include/protocols/timed.h b/include/protocols/timed.h index 18747be..d26b4a2 100644 --- a/include/protocols/timed.h +++ b/include/protocols/timed.h @@ -90,11 +90,13 @@ struct tsp { #define TSPTYPENUMBER 25 #ifdef TSPTYPES -const char *tsptype[TSPTYPENUMBER] = +static char const * const tsptype[] = { "ANY", "ADJTIME", "ACK", "MASTERREQ", "MASTERACK", "SETTIME", "MASTERUP", "SLAVEUP", "ELECTION", "ACCEPT", "REFUSE", "CONFLICT", "RESOLVE", "QUIT", "DATE", "DATEREQ", "DATEACK", "TRACEON", "TRACEOFF", "MSITE", "MSITEREQ", "TEST", "SETDATE", "SETDATEREQ", "LOOP" }; +_Static_assert(sizeof(tsptype) / sizeof(const char *) == TSPTYPENUMBER, + "Size of tsptype does not match TSPTYPENUMBER"); #endif #endif /* !_TIMED_H_ */ -- cgit v1.1