Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Opinion sought: Is this strictly conforming C? Date: Mon, 19 Feb 2018 13:59:13 -0800 Organization: None to speak of Lines: 49 Message-ID: References: <29e38fdf-86ef-4935-891a-b2683ee99b88@googlegroups.com> <42bf72ce-89a8-405e-9155-9fbebe4b6d31@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="7f521aeebfef0486b26d425b05818aac"; logging-data="9118"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mPB26alykCyCQFdfNxNie" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:RpeXIi+/InkJIrom4TDr5+6UgiQ= sha1:49y0y4/13Ny/64d8ZwOGTcX5Ky4= Xref: csiph.com comp.lang.c:126865 supercat@casperkitty.com writes: > On Monday, February 19, 2018 at 2:25:29 PM UTC-6, Tim Rentsch wrote: >> supercat@casperkitty.com writes: >> >> > C99 changed some rules from C89, [...] >> >> What changes are those? Specifically, which sections and >> paragraphs in the two Standards are you talking about? >> If you don't cite specific sections and paragraphs, along >> with a statement of what change you think was made in each >> case, you're just blowing smoke. > > From N1570 Annex J.2: > > -- An array subscript is out of range, even if an object is > apparently accessible with the given subscript (as in the > lvalue expression a[1][7] given the declaration int a[4][5]) > (6.5.6). > > I don't recall anything in C89 that would have implied that pointer > arithmetic would only be usable within an *inner* array object; indeed, > the biggest benefit to requiring that arrays not have padding between > rows is that such guarantee would allow multi-dimensional arrays to be > treated like flat arrays when needed. The C89/C90 definition of pointer addition is similar to the current definition. If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined. In the example in N1570, we have: int a[4][5]; a[1][7]; For a[1][7] to be valid, you'd have to have an array object of at least 8 int elements. I think (correct me if I'm mistaken) that you're assuming the declaration of a creates an object of type int[20]. Can you cite wording in the C89/C90 standard that supports this assumption? -- 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"