[BusyBox] compare structs without comparing all the fields ?
Firewall
bug1 at optushome.com.au
Sat Apr 20 11:29:04 UTC 2002
Is it possible to compare two structs without comparing all their fields ?
#define BITWIDTH_REVISION 9
typedef struct package_version_s {
unsigned short package:14;
unsigned short epoch:4;
unsigned short upstream:12;
unsigned short revision:BITWIDTH_REVISION;
} __attribute__ ((__packed__)) package_version_t;
Im trying to use the memcmp statement below to compare two variable of the
above type but the results arent always correct, i.e. there are cases
where the two variables fields have the same contents, but they arent
considered equal acording to memcmp.
if (memcmp(package_version, package_version_key,
sizeof(package_version_t)) == 0) {
If i compare the fields individually like this it works.
if ((package_version->package == package_version_key->package) &&
(package_version->epoch == package_version_key->epoch) &&
(package_version->upstream == package_version_key->upstream) &&
(package_version->revision == package_version_key->revision)) {
If i #define BITWIDTH_REVISION 8 then it fails less often...
You think you can trust a compiler and it turns around and does that to
you !
Glenn
More information about the busybox
mailing list