Bit fields - omówienie zagadnienia

Nasza ocena:

3
Wyświetleń: 749
Komentarze: 0
Notatek.pl

Pobierz ten dokument za darmo

Podgląd dokumentu
Bit fields - omówienie zagadnienia  - strona 1 Bit fields - omówienie zagadnienia  - strona 2

Fragment notatki:

Bit-fields • Used to store variables smaller than one byte • Example: - a set of single-bit flags - interfaces to hardware devices • The usual way: masks, shifting, masking, ... • An alternative in C: bit-fields • A bit-field , or field : a set of adjacent bits within a ''word'' • Syntax: similar to structures • Example: struct { unsigned int is_alpha : 1; unsigned int is_digit : 1; unsigned int is_other : 1; } flags; • flags contains three 1-bit fields • The number after colon is the field width in bits • Fields are declared unsigned int • Access: like in structures flags.is_alpha , flags.is_digit , etc. • Fields behave like small integers • Almost everything - implementation-dependent
- e.g. whether a field may overlap a word boundary
- whether fields are assigned from left to right or reverse
• Programs that depend on such things are not portable
• Unnamed fields (:width) are used for padding
• width 0: force alignment at the next word boundary
• Fields may be declared only as int s; for portability, specify signed or unsigned explicitly
• They are not arrays
- they do not have addresses
- the & operator cannot be applied on them.
... zobacz całą notatkę

Komentarze użytkowników (0)

Zaloguj się, aby dodać komentarz