From owner-svn-src-head@FreeBSD.ORG Tue Apr 9 16:16:35 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id EE2B1AB4; Tue, 9 Apr 2013 16:16:35 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id D10E165E; Tue, 9 Apr 2013 16:16:35 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r39GGZYS061680; Tue, 9 Apr 2013 16:16:35 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r39GGZeG061677; Tue, 9 Apr 2013 16:16:35 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201304091616.r39GGZeG061677@svn.freebsd.org> From: Ed Schouten Date: Tue, 9 Apr 2013 16:16:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r249311 - in head: include/protocols sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Apr 2013 16:16:36 -0000 Author: ed Date: Tue Apr 9 16:16:34 2013 New Revision: 249311 URL: http://svnweb.freebsd.org/changeset/base/249311 Log: 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. Modified: head/include/protocols/timed.h head/sys/sys/syslog.h head/sys/sys/ttydefaults.h Modified: head/include/protocols/timed.h ============================================================================== --- head/include/protocols/timed.h Tue Apr 9 15:35:26 2013 (r249310) +++ head/include/protocols/timed.h Tue Apr 9 16:16:34 2013 (r249311) @@ -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_ */ Modified: head/sys/sys/syslog.h ============================================================================== --- head/sys/sys/syslog.h Tue Apr 9 15:35:26 2013 (r249310) +++ head/sys/sys/syslog.h Tue Apr 9 16:16:34 2013 (r249311) @@ -69,7 +69,7 @@ typedef struct _code { int c_val; } CODE; -CODE prioritynames[] = { +static const CODE prioritynames[] = { { "alert", LOG_ALERT, }, { "crit", LOG_CRIT, }, { "debug", LOG_DEBUG, }, @@ -122,7 +122,7 @@ CODE prioritynames[] = { #define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) #ifdef SYSLOG_NAMES -CODE facilitynames[] = { +static const CODE facilitynames[] = { { "auth", LOG_AUTH, }, { "authpriv", LOG_AUTHPRIV, }, { "console", LOG_CONSOLE, }, Modified: head/sys/sys/ttydefaults.h ============================================================================== --- head/sys/sys/ttydefaults.h Tue Apr 9 15:35:26 2013 (r249310) +++ head/sys/sys/ttydefaults.h Tue Apr 9 16:16:34 2013 (r249311) @@ -95,10 +95,17 @@ * #define TTYDEFCHARS to include an array of default control characters. */ #ifdef TTYDEFCHARS -static cc_t ttydefchars[NCCS] = { - CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT, - CERASE2, CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT, - CDISCARD, CMIN, CTIME, CSTATUS, _POSIX_VDISABLE + +#include +#include + +static const cc_t ttydefchars[] = { + CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT, CERASE2, CINTR, + CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT, CDISCARD, CMIN, CTIME, + CSTATUS, _POSIX_VDISABLE }; +_Static_assert(sizeof(ttydefchars) / sizeof(cc_t) == NCCS, + "Size of ttydefchars does not match NCCS"); + #undef TTYDEFCHARS -#endif +#endif /* TTYDEFCHARS */