Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbosgd!gatech!seismo!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: type cast in initializer Message-ID: <979@brl-smoke.ARPA> Date: Sun, 16-Feb-86 00:30:16 EST Article-I.D.: brl-smok.979 Posted: Sun Feb 16 00:30:16 1986 Date-Received: Tue, 18-Feb-86 04:22:04 EST References: <302@hsi.UUCP> <1450@bbncc5.UUCP> <305@cray.UUCP> <269@spp3.UUCP> <392@ccivax.UUCP> Reply-To: gwyn@brl.ARPA Organization: /usr/local/lib/news/organization Lines: 22 In article <392@ccivax.UUCP> rb@ccivax.UUCP (What's in a name ?) writes: >In article <269@spp3.UUCP> ansok@spp3.UUCP (Gary Ansok) writes: >> >>Are there any other cases where casts are NEEDED besides: >> >> function calls: doub_var = sqrt((double) int_var); >> pointer punning: long_var = *(long *) char_ptr; >> > Yes, accessing members of structures. > ie: > struct x y; > struct i j; > i.memb=y.memb; /* some compilers hate this */ > should be written: > i.memb= ((struct i)x).memb; > > this is especially true if both structures contain 'memb' but > 'memb' is different type or placement. > A union is probably preferred. For the benefit of C novices: The above is nonsense; don't pay attention to it.