STRUCT padding q

R

Raj Pashwar

Hello Friends

In the case where a STRUCT receives padding bytes, either right at the
beginning, or right at the end, will it be GUARANTEED by ANSI C that
size_of(struct) will include those extremal padding bytes?

Regards
Raj
 
I

Ike Naar

In the case where a STRUCT receives padding bytes, either right at the
beginning, or right at the end, will it be GUARANTEED by ANSI C that
size_of(struct) will include those extremal padding bytes?

Yes.

From the C11 standard:

6.5.3.4 The sizeof and _Alignof operators
4 [...] When applied to an operand that has structure or union
type, the result is the total number of bytes in such an object,
including internal and trailing padding.

Note that there is no padding at the beginning of a struct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top