Talk:Stride of an array

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Untitled 1[edit]

Clarification 1

Quote from article:

  "locations in memory between successive array elements"

This statement could be a bit clearer. Is it referring to the space between elements (e.g. the gap between elements) or the distance from the start of one element to the start of the next element? After reading the ThreeBytesWide example, the answer to my question can be inferred however it would be useful to be more clear.

Clarification 2

Quote from article:

  "An array with stride 1 has elements which are contiguous in memory."

Since it is important to note when the stride is measured in bytes or in units, this article should be more explicit. How about this for a clarification?

  "An array with unit stride has elements which are contiguous in memory."

Due to not stating whether units or bytes are meant, the first statement might lead some to believe that only arrays with 1 byte elements can be contiguous. —Preceding unsigned comment added by 216.150.210.194 (talkcontribs) 12:03, July 23, 2007

Untitled 2[edit]

/* Print the contents of an array of ints with the given stride */
void print_some_ints(const int *arr, int length, size_t stride)
{
    int i;
    for (i=0; i < length; ++i) {
        printf("%d\n", arr[0]);
        arr = (int *)((unsigned char *)arr + stride);
    }
}

the arr param is declared const so, you cannot modify this. —Preceding unsigned comment added by Eridal (talkcontribs) 00:22, 11 May 2010 (UTC)[reply]

  • No, the parameter arr is not const; it is a non-const pointer to const int. It would be const if it were declared "[const] int *const arr". Musiphil (talk) 00:49, 23 June 2011 (UTC)[reply]

C and C++[edit]

Besides that in over 20 years of CS I never heard that term, the "stride" and sizeof() in C and C++ are always the same, that is sizeof(T[N]) == sizeof(T) * N. See for example 8.3.4 of ISO14882:2003(e) or 6.5.2.1 of ISO9899:1999(e) as well as 6.5.6 of ISO9899:1999(e) and 6.2.5-20 of ISO9899:1999(e). Also 6.5.3.4-6 of ISO9899:1999(e) is intresting here.

As such the whole reasoning of the non-unit-stride section is wrong, which is already indicated by the longer example using sizeof an array element as the "stride".

Furthermore the "overlapping parallel arrays" example is simply a hack using the ability of C to treat arbitrary memory as arbitrary types.

As long as this article does not cite any almost-authorative site on this topic I would suggest removing it alltogether, as in its current form it is somewher between half-baked-wrong and dangerous. — Preceding unsigned comment added by 213.61.9.75 (talk) 09:03, 20 July 2011 (UTC)[reply]

Bjarne Stroustrup mentions strides in The C++ Programming Language, fourth edition, third printing, page 131 and page 1172, and writes that they are a key feature of Fortran vectors etc. Chrisahn (talk) 22:34, 11 July 2016 (UTC)[reply]

char or unsigned char?[edit]

In C++, all sizes are measured relative to char. Whether char is signed or unsigned is implementation-defined. I assume it's the same in C. If so, the code example should use char instead of unsigned char. Chrisahn (talk) 22:46, 11 July 2016 (UTC)[reply]