[regarding]
if(CompareMyStr uctsForEquality (&z, &(struct mystruct){0}) == 1)
In article <bn**********@t itan.btinternet .com>
Richard Heathfield <bi****@eton.po wernet.co.uk> writes, in part:The construct &(struct mystruct){0}, which uses a "compound literal", is
C99-only.
Yes. In this particular case -- comparing, not writing on, the
structure -- you might want to use:
&(const struct mystruct){0}
i.e., add a "const" qualifier, provided the compare() function takes
const-qualified pointers. This not only makes the structure contents
read-only (at least in principle), but also informs the compiler that
it is allowed to share storage with other such "const struct mystruct"s.
In other words, barring particularly tricky optimization, the sequence:
extern void foo(const struct S *, const struct S *);
foo(&(struct S){0}, &(struct S){0});
*must* pass two *different* pointer values to function foo(), while
the call:
foo(&(const struct S){0}, &(const struct S){0});
is allowed (but not required) to pass identical pointer values to
foo(). If foo() consists of:
void foo(const struct S *a, const struct S *b) {
printf("in foo(): have %s pointers\n",
a == b ? "same" : "different" );
}
then the difference is visible and you can tell whether your C99
compiler implements the "share readonly compound-literal storage"
optimization.
(Disclaimer: this is all based on a C99 draft, and this sort of
fiddly stuff about precisely when and where storage is allocated is
the kind of thing that changes from draft to draft. :-) )
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.