address of structure == address of first member? (long)

Carl Paukstis carlp at iscuva.ISCS.COM
Thu Nov 24 02:59:19 AEST 1988


(Maybe I should take this to private mail, but it seems a couple of points
here may be of general interest..)

In article <8954 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <2172 at iscuva.ISCS.COM> carlp at iscuva.ISCS.COM (Carl Paukstis) [me]:
>>What other portability problems will I run into with this code?
...
>2.  You implicitly declare exit() as returning int, which is incorrect.

  Hmmm.  Since exit() _doesn't_ return, I never paid any attention to this.
  Call me sloppy, I guess.  I'll have to remember that.

...
>4.  You really ought to #include <string.h> to declare strcmp().

  Oops!  Actually, I thought of this after I nicely formatted the listing,
  and didn't want to mess up the line numbers.  (You believe that? :-)

>>... void * table ...
>
>>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?

Anyway, thanks to Doug (and Chris Torek in private mail) who both sort of
confirmed that this code is reasonably portable.
-- 
Carl Paukstis    +1 509 927 5600 x5321  |"The right to be heard does not
                                        | automatically include the right
UUCP:     carlp at iscuvc.ISCS.COM         | to be taken seriously."
          ...uunet!iscuva!carlp         |                  - H. H. Humphrey



More information about the Comp.lang.c mailing list