JustForTest
JustForTest

Reputation: 289

Local variable storage on memory in C

These days I am reading a document about stack overflow and found one sentence confused me.

Items that are pushed on the stack can, incidentally, only be put at word boundaries, meaning that the address must be a multiple of the word length. Hence if the program contains a local variable using only one byte, then nevertheless a full word is used to store this variable!

Does it means that a short int(2 bytes) local variable which is stored on stack of 32-bits machine will waste 2 bytes since the system will assign a full word to store?

Upvotes: 1

Views: 139

Answers (1)

littleadv
littleadv

Reputation: 20272

Yes, that's what it means. It depends on the system implementation and addressing implementation, but its pretty common to have word alignment.

Upvotes: 4

Related Questions