Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!rochester!ritcv!ccice5!ccivax!rb From: rb@ccivax.UUCP (rex ballard) Newsgroups: net.lang.c Subject: Re: type cast in initializer Message-ID: <392@ccivax.UUCP> Date: Tue, 11-Feb-86 22:37:56 EST Article-I.D.: ccivax.392 Posted: Tue Feb 11 22:37:56 1986 Date-Received: Fri, 14-Feb-86 06:06:47 EST References: <302@hsi.UUCP> <1450@bbncc5.UUCP> <305@cray.UUCP> <269@spp3.UUCP> Reply-To: rb@ccivax.UUCP (What's in a name ?) Organization: CCI Telephony Systems Group, Rochester NY Lines: 20 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.