←back to thread

387 points pedro84 | 1 comments | | HN request time: 0.248s | 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. kbenson ◴[] No.14862626[source]
> The problem is that a frightening number of people don't bother to write the half-dozen obvious wrappers around this

That's likely because having to pass it in and out of functions and libs that don't expect your special structure might cause it to have an invalid length, and then all your special wrappers can become a liability and not an advantage through either assuming your bufs are valid, or defensively checking more than is necessarily because they can't know whether it was altered or not.

> stdlib doesn't provide them either

Which is the real problem. That would make them a de facto standard, and a lot (but probably not all) of the problems would be mitigated by people accepting the performance trade offs needed to make them safe.