Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
ScottBurson
on Dec 22, 2016
|
parent
|
context
|
favorite
| on:
A convenient untruth: Array notation in C is a lie
Yes, and there's another inconsistency here as well. Arrays and pointers into arrays are accessed with the same syntax:
char a[3], *pa = a; ... a[0] ... pa[0] ...
In contrast, with a struct, you have to know which one you have and use the correct operator:
struct { int x; } s, *ps = &s; ... s.x ... ps->x ...
To be consistent, they could either have made '.' work in both cases, or forced you to write things like '(*pa)[0]'.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: