←back to thread

387 points pedro84 | 1 comments | | HN request time: 0s | source
Show context
Animats ◴[] No.14860964[source]
C's lack of array size info strikes again:

    memcpy(current_wmm_ie, ie->data, ie->len);
where "ie" points to data obtained from the net.
replies(2): >>14861129 #>>14861284 #
revelation ◴[] No.14861129[source]
C's lack of arrays strikes again. They are essentially syntactic sugar.
replies(1): >>14861235 #
frlnBorg ◴[] No.14861235[source]
What do you mean by C not having arrays?
replies(5): >>14861254 #>>14861256 #>>14861257 #>>14861262 #>>14861281 #
kinkrtyavimoodh ◴[] No.14861262[source]
It's syntactic sugar in the sense that arr[i] is just shorthand for *(arr+i)

There's no abstraction or 'concept' of arrays there. You are literally just telling the compiler to take a certain pointer and move i steps ahead.

replies(1): >>14861315 #
corndoge ◴[] No.14861315[source]
Isn't that the definition of an array? Chunk of contiguous memory plus a notion of how to subdivide it into equal parts?
replies(2): >>14861327 #>>14861945 #
kuschku ◴[] No.14861327[source]
Yes, exactly. A chunk of memory. A chunk has an end.

But "arrays" in C aren't a chunk of memory, just the info where it starts and how large elements are.

replies(1): >>14862551 #
hedora ◴[] No.14862551[source]
The problem is that a frightening number of people don't bother to write the half-dozen obvious wrappers around this, and stdlib doesn't provide them either:

struct buf { uint8_t * base, size_t size };

replies(2): >>14862626 #>>14862983 #
1. kbart ◴[] No.14862983[source]
That doesn't solve the problem because you still have to set 'size' manually.