Path: utzoo!attcan!uunet!iscuva!carlp From: carlp@iscuva.ISCS.COM (Carl Paukstis) Newsgroups: comp.lang.c Subject: Re: address of structure == address of first member? (long) Message-ID: <2176@iscuva.ISCS.COM> Date: 23 Nov 88 16:59:19 GMT References: <2172@iscuva.ISCS.COM> <8954@smoke.BRL.MIL> Organization: ISC Systems Corporation, Spokane, WA Lines: 39 (Maybe I should take this to private mail, but it seems a couple of points here may be of general interest..) In article <8954@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <2172@iscuva.ISCS.COM> carlp@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 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@iscuvc.ISCS.COM | to be taken seriously." ...uunet!iscuva!carlp | - H. H. Humphrey