Struct Address

Objective
  • Learn basics of data structures
  • Learn how memory may be padded within data structures

Review Basics

Here is the basic use of data structures in C:


Padding
  1. Use the struct below, and try this sample code
    • Note that there may be a compiler error in the snippet below that you are expected to resolve on your own
    • Struct should ideally be placed before the main() and the printf() should be placed inside of the main()
    • You should use your SJ embedded board because the behavior may be different on a different compiler or the board
  2. Now un-comment the packed attribute such that the compiler packs the fields together, and print them again.

Note:

  • Important: In your submission (could be comments in your submitted code), provide your summary of the two print-outs. Explain why they are different, and try to draw conclusions based on the behavior.
Back to top