address of structure == address of first member? (long)
Doug Gwyn
gwyn at smoke.BRL.MIL
Thu Nov 24 16:38:00 AEST 1988
In article <2176 at iscuva.ISCS.COM> carlp at iscuva.ISCS.COM (Carl Paukstis) writes:
->>86 code = strcmp (key, *(char **)((char *)table + (m * size)));
->Line 86 is okay, but you really don't need to cast to a (char**) then
->dereference to get the (char*) key. That's extra work that amounts to
->a no-op.
- Huh? The type of the expression ((char *)table + (m * size)) is
- "pointer to char", no? And the usage on line 86 requires "pointer to
- pointer to char". If I dereference the subexpression above, e.g.
- *((char *)table + (m * size)), the result type is "char", not "pointer
- to char" as required by strcmp(). Or am I just being dense?
That's not what I said!
You already had a (char *). You then cast it to (char **), and then
dereferenced that using the * operator. There was no need for these
extra steps when the original (char *) was just what you needed.
(strcmp takes (char *) arguments.)
More information about the Comp.lang.c
mailing list