Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Stride of an array
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Overlapping parallel arrays=== Some languages allow [[AoS_and_SoA#Array of structures|arrays of structures]] to be treated as overlapping [[parallel array]]s with non-unit stride: <syntaxhighlight lang="c"> #include <stdio.h> struct MyRecord { int value; char *text; }; /** Print the contents of an array of ints with the given stride. Note that size_t is the correct type, as int can overflow. */ void print_some_ints(const int *arr, int length, size_t stride) { int i; printf("Address\t\tValue\n"); for (i=0; i < length; ++i) { printf("%p\t%d\n", arr, arr[0]); arr = (int *)((unsigned char *)arr + stride); } } int main(void) { int ints[100] = {0}; struct MyRecord records[100] = {0}; print_some_ints(&ints[0], 100, sizeof ints[0]); print_some_ints(&records[0].value, 100, sizeof records[0]); return 0; } </syntaxhighlight> This idiom is a form of [[type punning]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)