STRUCT padding q

Discussion in 'C Programming' started by Raj Pashwar, Jul 17, 2012.

  1. Raj Pashwar

    Raj Pashwar Guest

    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
    Raj Pashwar, Jul 17, 2012
    #1
    1. Advertising

  2. Raj Pashwar

    Ike Naar Guest

    On 2012-07-17, Raj Pashwar <> wrote:
    > 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.
    Ike Naar, Jul 17, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Fogelklou
    Replies:
    36
    Views:
    1,353
    Chris Fogelklou
    Apr 20, 2004
  2. edware

    struct padding

    edware, Apr 25, 2006, in forum: C Programming
    Replies:
    9
    Views:
    431
    Ed Vogel
    Apr 27, 2006
  3. Hallvard B Furuseth

    Padding bits and struct assignment

    Hallvard B Furuseth, Dec 27, 2006, in forum: C Programming
    Replies:
    5
    Views:
    629
    Eric Sosman
    Dec 27, 2006
  4. Replies:
    11
    Views:
    865
  5. Replies:
    13
    Views:
    341
    glen herrmannsfeldt
    May 5, 2013
Loading...

Share This Page