Timeline for What's the justification for implicitly casting arrays to pointers (in the C language family)?
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
4 hours ago | comment | added | IMSoP | I don't think it's quite right to contrast C only with languages which came later - at the time C was invented, Fortran had been around for 20 years, with subscripted variables which weren't considered syntax sugar for pointers. The account quoted in my answer suggests Ritchie was well aware of other techniques, but chose not to use them. | |
9 hours ago | comment | added | Barmar |
@RememberMonica int arr[5]; int *p = arr; p = arr+1; /*OK*/ arr = p+1; /* not OK */
|
|
11 hours ago | comment | added | Remember Monica | @Barmar You can only assign to lvalues, which pointers are generally not: int *x; (x+1)=5 | |
15 hours ago | comment | added | Barmar |
That sentence is also wrong. Arrays are not pointers. You can assign to pointers, to make them point somewhere else, but you can't assign to arrays. An array of pointers is not the same as a 2-dimensional array. sizeof treats them differently.
|
|
15 hours ago | comment | added | Bergi | @Barmar You seem to have skipped over the next sentence | |
16 hours ago | comment | added | Barmar | Arrays don't decay into pointers when you pass them to a function. Yes, they do. Arrays decay to pointers whenever they're used as rvalues. See stackoverflow.com/questions/1461432/… | |
19 hours ago | history | answered | bta | CC BY-SA 4.0 |