type cast in initializer

Doug Gwyn gwyn at brl-smoke.ARPA
Sun Feb 16 15:30:16 AEST 1986


In article <392 at ccivax.UUCP> rb at ccivax.UUCP (What's in a name ?) writes:
>In article <269 at spp3.UUCP> ansok at 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.



More information about the Comp.lang.c mailing list