Hrrmmm shouldn't those lines be...
Russ Allbery
rra at stanford.edu
Thu Sep 7 21:00:44 UTC 2000
Rick Irving <rirving at onecall.net> writes:
> Hrrmm.... Maybe it is just me, but, in file dbz.c, shouldn't line 1118
> read...
> < memcpy(&evalue.hash, &srch.hash,
> > memcpy(evalue.hash, &srch.hash,
> and 1511 read
> < if (!memcmp(&value.hash, &sp->hash, DBZ_INTERNAL_HASH_SIZE)) {
> > if (!memcmp(value.hash, &sp->hash, DBZ_INTERNAL_HASH_SIZE)) {
> The element -is- an array.
> Can someone correct me on this ?
They're equivalent. I find the second choice better as a matter of style,
but I'm pretty sure they should always compile to the same thing:
windlord:/tmp> cat testing.c
#include <stdio.h>
struct test {
char array[50];
};
int main(void) {
struct test test;
printf ("%x %x\n", test.array, &test.array);
}
windlord:/tmp> gcc -o testing testing.c
windlord:/tmp> ./testing
effff828 effff828
test.array is an array object, which when passed to a function degrades to
a pointer to the first element of the array. &test.array is a pointer to
an array. While these are different pointers (sizeof and pointer
arithmetic will behave differently on them), they're equivalent when cast
to a void * as they are when being passed to memcmp.
--
Russ Allbery (rra at stanford.edu) <http://www.eyrie.org/~eagle/>
More information about the inn-workers
mailing list