Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Tue, 13 May 2025 14:35:06 -0700 Organization: None to speak of Lines: 49 Message-ID: <87sel8nqid.fsf@nosuchdomain.example.com> References: <20250413072027.219@kylheku.com> <20250415153419.00004cf7@yahoo.com> <86h62078i8.fsf@linuxsc.com> <20250504180833.00000906@yahoo.com> <86plggzilx.fsf@linuxsc.com> <86ldr4yx0x.fsf@linuxsc.com> <1000cs3$2234m$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Tue, 13 May 2025 23:35:06 +0200 (CEST) Injection-Info: dont-email.me; posting-host="7bebadcbd12bf891ae6434de1ab23fbd"; logging-data="2156222"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/q0ewABwwUYrK5SgqB1q2x" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:WJrA9A9ZJdTSVPXugGXk5TTpcq4= sha1:tMc/ZhuPH55J2uBUpg5FqNvHVbg= Xref: csiph.com comp.lang.c:393385 Janis Papanagnou writes: > On 12.05.2025 17:08, David Brown wrote: >> On 11/05/2025 23:43, James Kuyper wrote: > [...] >>> More precisely, it makes it undefined behavior for values to point to an >>> array of less than 10 doubles. >> >> The wording of the C standard (C11, as that's what I have open at the >> moment) is : >> >> """ >> If the keyword static also appears within the [ and ] of the array type >> derivation, then for each call to the function, the value of the >> corresponding actual argument shall provide access to the first element >> of an array with at least as many elements as specified by the size >> expression. >> """ > > Oh! - This is somewhat surprising to me. - When I first read about > the "arr[static N]" I assumed that it would be possible to pass any > sub-array, say "&arr[8]" (or "arr+8") as long as it's large enough > to still have N elements from the starting point, but the quote says > explicitly "access to the _first_ element of an array" (which I'd > interpret as "&arr[0]" (or "arr"). - Unless I misinterpreted that; > what would be the reason for that? My personal interpretation is that this: void func(int arr[static 5]) { } int main(void) { int arr[10]; func(arr+5); // OK // func(arr+6); // UB } is valid, because, for example, the last 5 elements of a 10-element array object can be treated as a 5-element array object. gcc seems to agree, based on the fact that it warns about func(arr+6) but not about func(arr+5). This is a fundamental part of my mental model of C, but in a few minutes of searching I wasn't able to find explicit wording in the standard that supports it. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */