user3810155
user3810155

Reputation:

Does `alignof(N) == sizeof(N)` where N is an integral type?

Does alignof(N) == sizeof(N) where N is an integral type?

I'm asking for both C and C++, hope this isn't a problem.

Upvotes: 2

Views: 168

Answers (2)

user464502
user464502

Reputation: 2373

In C not necessarily. At least I can't find anything in the draft C99 or draft C11 standard that would require them to be the same. An implementation could theoretically have padding bits in its integer types, and it's easy to envision some machine architecture where the alignment requirement was smaller than the size. Consider a 64 bit integer on a system that only needed four byte alignment.

Upvotes: 2

jthill
jthill

Reputation: 60275

It's machine-specific. On a 32-bit machine, alignof(int64_t) could easily be 4. Too, assumptions that are widespread now won't be for so very long.

Upvotes: 4

Related Questions