On 21.08.2014 11:33, Branko Čibej wrote: > On 21.08.2014 10:44, Evgeny Kotkov wrote: >> >> I am wondering, whether this is a portable way of comparing structs. > > It is not. The portable way is to use the '==' operator.
... in C++, that is ... memcmp is not even safe (in general) if the struct is initialized to a known value (e.g., with memset to 0), because the compiler is allowed to use the struct padding any way it likes; and a function-local struct may not even exist on the stack until the memcmp is called, causing the compiler to spill its contents onto the stack. The only really portable way to compare structs is to (recursively) compare its members using '=='. That said, I've yet to see a platform where memcmp after memset (or calloc) didn't work. -- Brane -- Branko Čibej | Director of Subversion WANdisco | Realising the impossibilities of Big Data e. br...@wandisco.com