Flag has three 1 bit fields struct unsigned int

Info icon This preview shows pages 6–11. Sign up to view the full content.

View Full Document Right Arrow Icon
/* flag has three 1-bit fields */ struct { unsigned int is_keyword : 1; unsigned int is_extern : 1; unsigned int is_static : 1; } flag; flag.is_extern = flag.is_static = 1; flag.is_extern = flag.is_static = 0; if (flag.is_extern == 0 && flag.is_static == 0) printf("internal and auto\n"); CSC180 Fall 2008, University of Toronto 5
Image of page 6

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Example: struct flag_t { unsigned int is_a: 1; unsigned int is_b: 1; unsigned int is_c: 1; unsigned int is_d: 1; unsigned int is_e: 1; unsigned int is_f: 1; unsigned int is_g: 1; unsigned int is_h: 1; }; Note: we cannot use & to get the addresses of bit-fields. Fields can have no name; unnamed fields are used for padding. struct file_time { unsigned int : 5; /* not used */ CSC180 Fall 2008, University of Toronto 6
Image of page 7
unsigned int min : 6; unsigned int hour : 5; }; struct file_time ft; ft.min = 20; ft.hour = 12; Special field width 0 may be used to align b at the beginning of a storage unit. struct s { unsigned int a : 4; unsigned int : 0; unsigned int b : 8; }; CSC180 Fall 2008, University of Toronto 7
Image of page 8

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Exercise: compute sizeof(struct s) and sizeof(struct t) . struct s { unsigned int a : 4; unsigned int : 0; unsigned int b : 8; }; struct t { unsigned int a : 4; unsigned int b : 8; }; CSC180 Fall 2008, University of Toronto 8
Image of page 9
Complicated declarations Examples: int *f(); /* f: function returning pointer to int */ int (*pf)(); /* pf: pointer to function returning int */ char **argv; /* argv: pointer to pointer to char */ char (*daytab)[13];
Image of page 10

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern