Hacker News new | ask | show | jobs
by leetcrew 2196 days ago
a c array is literally just a sequence of objects in memory (possibly with padding, but you can ignore that for a while). you can think of pointing "exactly" to the first element as being equivalent to pointing to the whole array. you need to know where the array begins and its size to do anything with it. but once you know where it starts, you can access the next element by adding sizeof(char) (or whatever the element type happens to be) to the pointer.
1 comments

> possibly with padding

What padding?

If you declare a structure of unaligned size, the compiler might (probably must) introduce some padding bytes at the end of the structure to fit the alignment. In some architectures you cannot do unaligned accesses (ARM for example).

Unless you pack the structure with the alignment you want.

Yes, so the structure itself has padding (added by the compiler). But that is regardless of whether it is in an array or not. OP seemed to suggest that C arrays introduce padding of some sort, which they do not.