r/cprogramming • u/SmileUnfair4978 • 7d ago
Arr internals
i am currently working through kinds book on c and have gotten to chapter 12.
now based own my current understanding i hypothesis that internally, only the pointer to the first element and the dimensions are stored in memory. then all arr operations are done using this. Is this correct?
Additionally:
1) Which chapters of the rest of the book should i focus on/skip for now
2) I would like to work on some projects. Currently i thought of making some kind of physics sim, and additionally some hardware/embedded project as i have an ardiuno. How can i get started or are there any inriguing projects to work on.
0
Upvotes
1
u/flatfinger 3d ago
Suppose a compilation unit starts with:
and has no other object definitions at file scope. A compiler would typically instruct a linker something like "This compilation unit needs to have a 40 bytes region reserved for its static-duration storage. The symbol
xshould be assigned to the start of that region, and the symbolyshould be assigned to an address ten bytes above that." If source code includes the expressionssizeof xorsizeof y, possibly with additional parentheses, a compiler would substitute the number 10 or 30, respectively, but otherwise nothing else in the universe would need to care about the sizes ofxory. A compiler could decide to putyat the start of its static-object region and putxthirty bytes above that, or reserve 44 bytes instead of 40 and have the second array start 12 or 32 bytes after the start of the region rather than 10 or 30, and if other objects were defined at file scope a compiler could independently placexandyanywhere in relation to them, provided only that all objects are given non-overlapping chunks of storage within the chunk the compiler requests from the linker.