Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Speeding code

Author: Dieter Buerssner

Date: 10:36:44 05/13/03

Go up one level in this thread


>IIRC, ANSI-C requires structure assignments.

Correct.

>I haven't met a C compiler without struct assignments for many years, now,
>and I've never seen an ANSI compliant one without it.

Same here. The last I could remember was some Dec C Compiler for Vax/VMS. It
didn't support prototypes either and still had support for things like i =- j;
(meaning i -= j;)

The first edition of Kerninghan and Ritchie's book (which was before the ANSI
Standard, and might be considered as some sort of pre ANSI Standard) did not
have struct assignments.

>Hence: if you want to copy a structure, assign it.
>
>There is only one possible pitfall with this, I'm aware of:
>if you later want to compare two structs with "memcmp" instead of
>component by component, you also compare the "alignment gaps" of the
>structures (if there are any).  And the assignment _may_ omit copying the
>gaps (copying component by component).
>That may result in "unequal" results of memcmp(), although all components
>are equal.

Yes. But using memcmp() for comparing structures seems to have only very limited
use anyway. When you have been very careful, you could find copies produced by
memcpy. But typically, I guess one would also want to find out equal structures,
that were not produced by memcpy. For example some members were calculated, etc.
For specific platforms memcmp might work well, but I think it can't for Standard
C. Another thing that comes to my mind in this context. For example the old x86
far pointers. Two pointers can have a different representation, while still
pointing to the same thing. So if (p1==p2) could be true, while
memcmp(&p1,&p2,sizeof p1) would return something != 0. And such a pointer could
be inside a struct. Floating point numbers may have a similar problem, even when
otherwise well defined through IEEE floating point standards (for example +0 and
-0). So, not only filling bytes are a problem in this regard.

Cheers,
Dieter





This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.