Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: address of structure == address of first member? (long) Message-ID: <8954@smoke.BRL.MIL> Date: 22 Nov 88 09:29:51 GMT References: <2172@iscuva.ISCS.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 22 In article <2172@iscuva.ISCS.COM> carlp@iscuva.ISCS.COM (Carl Paukstis) writes: >What other portability problems will I run into with this code? 1. Use of prototypes constrains you to a modern compiler. 2. You implicitly declare exit() as returning int, which is incorrect. 3. sizeof results in a size_t but mybsearch() wants an int. Although the type is automatically converted in the scope of the prototype, if you tried to use a really large struct the size might not fit. 4. You really ought to #include to declare strcmp(). >86 code = strcmp (key, *(char **)((char *)table + (m * size))); >Line 86 bothers me. Is it permissible to cast a void* into a char* and do >arithmetic on it like this? Line 89 would have the same problem (if any). 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. >On machines (environments?) with non-byte-sized chars, is there a better >way to do the necessary arithmetic? Or what else have I missed? That seems about as good as any, if you don't want to tailor individual versions to specific systems.