What is meaning of "unsigned int Date :5;" in structure ?
Solved
C++ Gurus
-
I have seen one code where i found structure declared like below. i want to know what is meaning of
unsigned int Date :5;
in this structure ?
struct structDateStamp { unsigned int Date :5; unsigned int Month :4; unsigned int Year :5; unsigned int Hour :5; unsigned int Min :6; unsigned int Sec :6; };
-
@Qt-embedded-developer This struct is a bit-field, see https://docs.microsoft.com/en-us/cpp/cpp/struct-cpp?view=msvc-170
Date consumes first 5 bits, Month next 4 and so on. -
@Qt-embedded-developer I actually had to look that up!
Those are bit fields. Basically, the number after the colon describes how many bits that field uses. -