{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Bit Field Types

Bit Field Types - expecting a particular type for example...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Bit Field Types Here's a small difference between C and C++. In ANSI C, bit fields must be of type "int", "signed int", or "unsigned int". In C++, they may be of any integral type, for example: enum E {e1, e2, e3}; class A { public: int x : 5; unsigned char y : 8; E z : 5; }; This extension was added in order to allow bit field values to be passed to functions
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: expecting a particular type, for example: void f(E e) { } void g() { A a; a.z = e3; f(a.z); } Note that even with this relaxation of C rules, bit fields can be problematic to use. There are no pointers or references to bit fields in C++, and the layout and size of fields is tricky and not necessarily portable....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online