Groups | Search | Server Info | Login | Register


Groups > comp.lang.c > #396722

Re: Loops (was Re: do { quit; } else { })

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: Loops (was Re: do { quit; } else { })
Date 2026-03-01 23:37 -0800
Organization None to speak of
Message-ID <87y0kasmug.fsf@example.invalid> (permalink)
References (16 earlier) <86ecwsvunb.fsf@linuxsc.com> <87sel7c3y6.fsf@nosuchdomain.example.com> <865xi3x22i.fsf@linuxsc.com> <87h61nbvlo.fsf@nosuchdomain.example.com> <86cy1mg4h5.fsf@linuxsc.com>

Show all headers | View raw


Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
[...]
>> Can you define, preferably in something approaching standardese, what
>> you mean by "array" and by "array object", and in particular how they
>> differ?
>
> The difference is contextual.  A declaration such as 'int a[5];', at
> file scope, declares and defines an array object.  The value of a
> pointer returned by malloc() may be used to access an array of
> elements, but there is nothing that says the region of memory
> allocated by malloc() is an array object, only that it may be
> accessed as an array.

I was looking for *definitions* of the terms "array" and "array
object" that would help me understand how you're using the terms
and how they differ.  Examples can be helpful, but I would like to
see definitions that do not depend on examples.

I do not see any such definitions in anything you've written.

The standard defines the terms "object" and "array type".  If there's
a definition for the word "array" by itself, I haven't found it.

>> I believe that, in my example above, arr+5 *does* "provide access
>> to an array" with at least 5 elements.  (I also believe that that
>> "array" is an "array object".)  My difficulty is in demonstrating
>> this based on the normative wording in the standard.  *Maybe*
>> if you could explain the distinction you make between "array" and
>> "array object" it would help.
>
> Suppose we have a file scope declaration
>
>    int foo[10];
>
> and an expression
>
>    (foo+5)[-3];
>
> the behavior of the [] operation is described by the implied +
> operation in the section for Additive operators, with P being
> the subexpression (foo+5).  The region of memory corresponding
> to the fifth through ninth elements of foo surely is an array,
> but it is not the "array object" referred to by that paragraph
> in the C standard.  This point shows why it is imporant to
> distinguish between "array" and "array object".  All array
> objects are arrays, but not all arrays are array objects, as
> those terms are used in the C standard.

If I understand you correctly, you assert that given

    int foo[10];

the region of memory named "foo" is both an "array" and an "array
object" (of type int[10]), but for example the region of memory
containing the last 5 elements of foo is an "array" but not an
"array object".  Is that an accurate statement about your view?

I would say that the latter region is a region of memory in the
execution environment, the contents of which can represent a value of
the array type int[5] -- i.e., it can be treated as an array object,
and that it *is* an array object.  (A "value", of course, is the
"precise meaning of the contents of an object when interpreted as
having a specific type"; for an array type, that value consists of
the values of its elements.)

[...]

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Find similar


Thread

Re: Loops (was Re: do { quit; } else { }) Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-03-01 21:55 -0800
  Re: Loops (was Re: do { quit; } else { }) Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-03-01 23:37 -0800

csiph-web