0

I want to know if I had such a construction:

typedef struct {
    char element;
} element_t;

So now is the condition:

sizeof(elem.element) == sizeof(element_t) == 1

true only for some architectures or it is always like that? I mean, any alignment can occur here, so can it be:

(sizeof(elem.element) == 1) != (sizeof(element_t) == 4)

if data in structures are aligned to 4-byte boundaries in a 32-bit architecture.

1 Answer 1

2

sizeof(elem.element) is guaranteed to be 1 (but there is no guarantee that it will hold only 8 bits).

There is no guarantee that sizeof(element_t) == 1, though on all practical architectures, I believe it will be of size 1.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.