Problem 1. For each struct variable declared below, suppose the address of the first byte of the variable is z. Give the bytes of each field of the variable, and the total number of bytes occupied by the variable. You may assume that r is Don't forget about alignment restrictions (Text section 3.9.3)! For example: struct { int eggs; long chickens; char name [10];

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
b.
S
d.
struct {
char c;
short w;
int t;
long *foo;
} silly;
struct {
int i;
int j;
unsigned long foo;
long bar;
} record;
struct {
short qscores [4];
short halfs [2] ;
int overunder;
int spread;
} bline;
For this problem, give the address of the second element of each array (i.e., blineqscores[1].
and blinehalfs[1]), instead of the beginning of each array.
Transcribed Image Text:b. S d. struct { char c; short w; int t; long *foo; } silly; struct { int i; int j; unsigned long foo; long bar; } record; struct { short qscores [4]; short halfs [2] ; int overunder; int spread; } bline; For this problem, give the address of the second element of each array (i.e., blineqscores[1]. and blinehalfs[1]), instead of the beginning of each array.
Problem 1. For each struct variable declared below, suppose the address of the first byte of the
variable is r. Give the bytes of each field of the variable, and the total number of bytes occupied
by the variable. You may assume that z is Don't forget about alignment restrictions (Text section
3.9.3)!
For example:
struct {
int eggs;
long chickens;
char name [10];
} henhouse;
Because of alignment, the compiler will leave (empty and useless) space (padding) between eggs
and chicken, because the latter must be 8-byte-aligned which the former is only 4 bytes long. So
we have the address of eggs is r; chickens is £ +8, and the character array name starts at x + 16.
The compiler also leaves a gap of six bytes at the end, so the end of the variable also aligned to an
8-byte boundary. So the size of the structure is 32 bytes (not 26).
a.
struct {
long q;
int 1;
short w;
char b1;
char b2;
} mystruct;
Transcribed Image Text:Problem 1. For each struct variable declared below, suppose the address of the first byte of the variable is r. Give the bytes of each field of the variable, and the total number of bytes occupied by the variable. You may assume that z is Don't forget about alignment restrictions (Text section 3.9.3)! For example: struct { int eggs; long chickens; char name [10]; } henhouse; Because of alignment, the compiler will leave (empty and useless) space (padding) between eggs and chicken, because the latter must be 8-byte-aligned which the former is only 4 bytes long. So we have the address of eggs is r; chickens is £ +8, and the character array name starts at x + 16. The compiler also leaves a gap of six bytes at the end, so the end of the variable also aligned to an 8-byte boundary. So the size of the structure is 32 bytes (not 26). a. struct { long q; int 1; short w; char b1; char b2; } mystruct;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY