Re: A Certain Size/sizeof

From: Gene Wirchenko (gwirchenkoEXCEPT_at_CAPITALSwencomine.com)
Date: 11/15/03


Date: Fri, 14 Nov 2003 23:47:32 GMT

On Fri, 14 Nov 2003 18:19:28 -0500, Robert W Hand
<rwhand@NOSPAMoperamail.com> wrote:

[snip]

>count should have the number of rows in the array. Let's take it from
>the beginning. Note that I shall indicate the object array as arr to
>avoid hopeless confusion in the following note.
>
>arr is an array that has 17 columns. The number of rows is determined
>by the initializer. sizeof is an operator that works on the compiler
>side. It determines the size of the object operand in bytes.
>
>So sizeof arr will be the number of bytes that is in arr. Such a size
>will be implementation defined. Note that when the operand of sizeof
>is an array, the array does not decay into a pointer to some type.
>
>arr is an array of an array of 17 ints. When used as the operand of
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>the indirection operator, arr decays into a pointer into an array of
>17 ints. So applying the indirection operator to arr results in an
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>array of 17 ints. When the sizeof operator is then applied, the
 ^^^^^^^^^^^^^^^^^
>resulting array will not decay further. Rather it will yield the size
>of each row in bytes.
>
>So dividing sizeof arr by sizeof *arr will be the number of rows in
>the object array, arr.

     That was a very clear explanation. I could follow it
step-by-step. The above were the missing bits (for me).

     Thank you.

><Observation>
>Reading the "arguments" of both sides, I really do not see any reason
>for further anger. It reads like a misunderstanding by both parties.
>Please kiss and make up. ;-)
></Observation>

Sincerely,

Gene Wirchenko



Relevant Pages

  • Re: Evaluating unary *
    ... 'arr' exists, ... value can be used with the same syntax as would be used to access a 2D array of the kind you're referring to, but that 2D array is just a different way of looking as the same object that was already created by the definition of 'arr'. ... to me, it makes sense to return a pointer to the first value of an array, but to return the address of the pointer to the first value of an array, is not directly possible as such. ... lea eax, ...
    (comp.std.c)
  • Re: A Certain Size/sizeof
    ... Note that I shall indicate the object array as arr to ... So sizeof arr will be the number of bytes that is in arr. ... So applying the indirection operator to arr results in an ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Evaluating unary *
    ... value can be used with the same syntax as would be used to access a 2D array of the kind you're referring to, but that 2D array is just a different way of looking as the same object that was already created by the definition of 'arr'. ... the expression &arr requires no special handling beyond insertion of the appropriate address into a suitable register. ... to me, it makes sense to return a pointer to the first value of an array, but to return the address of the pointer to the first value of an array, is not directly possible as such. ... It does create a pointer value which points at arr itself, and treats the entirety of arr as the first element in an array containing exactly one element of type int. ...
    (comp.std.c)
  • Re: multi dimensional arrays as one dimension array
    ... Are you of the opinion that one or both of memcpy(p, arr, sizeof arr) ... way of converting a two-dimensional array into a one-dimensional ... &arr) is supposed to be pointer constrained legally to range over ... arrays of character type and other objects treated as arrays ...
    (comp.lang.c)
  • Re: C Coding style question
    ... Given a definition of an array like this: ... use sizeof (fails when someone changes arr from an array to a pointer): ... memcpy(arr, src, sizeof arr); ...
    (comp.arch.embedded)