Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Effect of CPP tags Date: Sun, 07 Jan 2024 16:06:04 -0800 Organization: None to speak of Lines: 74 Message-ID: <87o7dwr8nn.fsf@nosuchdomain.example.com> References: <%cFlN.140487$xHn7.115393@fx14.iad> <20240106193126.377@kylheku.com> <87wmskrckc.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="f909ce6842d964f6deb0fc108ae5e13b"; logging-data="1326226"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eE+I0EHwAsz/l3nrW5RN3" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:9rfwVWGmaFaa3IVlQOcl8xVcb0Q= sha1:iRkyYNrcuZIAFjZN2zTxi6ib6TA= Xref: csiph.com comp.lang.c:379919 Bart writes: > On 07/01/2024 22:41, Keith Thompson wrote: >> Bart writes: > >>> So, C has distinct concepts of 'zero-length' array and 'unbounded >>> array', so that sizeof/sizeof on the latter generates a diagnostic. > >> No, it doesn't. C doesn't have zero-length arrays. A fixed-length >> array with a length of 0: >> int arr[0]; >> is a constraint violation. > > So you can't have an array with an empty initialiser list either? An empty initializer list is a syntax error. (It will be allowed in C23.) > I must say you have to try quite hard to get a diagnostic for those! Why must you say that when it isn't true? $ cat c.c int arr[] = {}; $ gcc -c c.c $ gcc -std=c17 -pedantic c.c c.c:1:13: warning: ISO C forbids empty initializer braces [-Wpedantic] 1 | int arr[] = {}; | ^ c.c:1:5: error: zero or negative size array ‘arr’ 1 | int arr[] = {}; | ^~~ $ > So what happens if you have a generated data block for example, > containing N items; it only works when N is at least 1? Yes. > What are you > supposed to do when N is zero? Something else, I suppose. > It sounds quite a limitation. Since I have no agenda here, I won't try to quantify how much of a limitation it is. >> I don't know what you mean by "unbounded array". > > One without a bound specified? C might call it 'incomplete', even > though the syntax is common; this is one example of many: > > void F(int A[]) {} That's a particularly bad example, since A, being a parameter, is of pointer type. int[] is an incomplete type. You can't create objects of incomplete types, and you can't apply sizeof to incomplete types. The C standard uses the word "unbounded" a few times, but only in reference to mathematical functions, not arrays. Incomplete array types have no particular relationship to VLAs. When you brought up "unbounded arrays", you seemed to be talking about array objects whose length can change during their lifetime. C has no such feature. Do you understand that? -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */