KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Suppose I have the following structure: typedef struct { unsigned field1 :1; unsigned field2 :1; unsigned field3 :1; } mytype; The first 3 bits will be usable but sizeof(mytype) will return 4 which means 29 bits of padding. My question is, are these padding bits guaranteed by the standard to be zero initialized by the statement: mytype testfields = {0}; or: mytype myfields = {1, 1, 1}; Such that it's safe to perform the following memcmp() on the assumption that bits 4..29 will be zero and therefore won't affect the comparison: if ( memcmp(&myfields, &testfields, sizeof(myfields)) == 0 ) printf("Fields have no bits set\n"); else printf("Fields have bits set\n");
Tags (comma-separated)
Save Edits
Cancel