Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: EXIT_SUCCESS Date: Mon, 25 Jul 2016 11:04:19 -0700 Organization: None to speak of Lines: 35 Message-ID: References: <87r3b4xdsa.fsf@gmail.com> <6f1e2608-eac3-49ea-a5f4-0fdc746b2942@googlegroups.com> <579638b1.119218@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="23822"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DCVJVLAWzdd3Ayo8KE5YY" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:P1x8pvEcfvnXNyb+JlMxIw1lqWg= sha1:Hza5PhiERyTLhKQUBPfToLN3clA= Xref: csiph.com comp.lang.c:91041 Richard Heathfield writes: > On 25/07/16 17:06, Richard Bos wrote: >> Richard Heathfield wrote: >> >>> On 25/07/16 12:42, jgh@mdfs.net wrote: >> >>> static const char *get_foo(size_t a) >>> { >>> static const char *numbers[] = >>> { >>> "zero", >>> "one", >>> "two", >>> "three", >>> "four" >>> }; >>> size_t maxval = sizeof numbers / sizeof numbers[0] - 1; >>> >>> return numbers[a <= maxval ? a : maxval]; >>> } >> >> A good solution, > > A slightly better solution (which, of course, I thought of /after/ > posting) would have been to make maxval static. And const? [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"