On Thu, Aug 21, 2014 at 1:17 PM, Branko Čibej <br...@wandisco.com> wrote:
> 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. > > Changed in r1619358 and 1620602. Thanks everyone! -- Stefan^2.