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: Two C code questions Date: Tue, 14 Mar 2017 11:49:58 -0700 Organization: None to speak of Lines: 27 Message-ID: References: <468c93a0-7b2d-4eab-8266-39737867b9ac@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="68145e82dff5cec9d4077a7833a68c0b"; logging-data="29072"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AWKCyrjL9MYCl3MqqApvc" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:5K3EOEBILiXpP+6JIa3h1eZQldU= sha1:BqvZPTuzTOtf3RGLws7o+lP+6u4= Xref: csiph.com comp.lang.c:106069 John Bode writes: > On Monday, March 13, 2017 at 10:45:53 PM UTC-5, Mehdi Amini Valashani son of Bahram wrote: [...] >> int main(void) >> { >> uint64_t ui[N] = {0}; >> > > For C89 and earlier, array dimensions must be *constant expressions*; i.e., > something that can be evaluated at compile time (integer literals, sizeof > expressions, macros that expand to either literals or sizeof expressions, > arithmetic expressions that involve any of the previous, etc.). > > A variable declared as "static const" is *not* a constant expression - its > value is not evaluated at compile time. > > C99 introduced variable-length arrays, whose size doesn't have to be > established until run time; if you compiled that code under a C99 compiler, > it should work. No, C99 doesn't allow VLAs to be initialized (nor does C11). -- 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"