Path: utzoo!telly!ddsw1!lll-winken!killer!texbell!uhnix1!nuchat!uunet!convex!texsun!pitstop!sun!david From: david@sun.uucp (David DiGiacomo) Newsgroups: gnu.gcc Subject: Re: left-hand side cast Message-ID: <78888@sun.uucp> Date: 23 Nov 88 02:18:21 GMT References: <8811221620.AA25541@ee.ecn.purdue.edu> Organization: Sun Microsystems, Inc. - Mtn View, CA Lines: 36 In article <8811221620.AA25541@ee.ecn.purdue.edu> lewie@EE.ECN.PURDUE.EDU (Jeff Lewis) writes: >Say you needed to push arbitrary sized data onto a stack: > > int *sp, foo; > short int *sp2, bar; > unsigned char *sp3, biff; > > *sp++ = foo; > sp2 = (short int *) sp; > *sp2++ = bar; > sp3 = (unsigned char *) sp2; > *sp3++ = biff; > sp = (int *) sp3; > ... This is not a good example to support the use of lvalue casts. Ordinary rvalue casts will clean it up nicely. #define PUSH(sp, item) \ (* (typeof (item) *) (sp) = (item), ((sp) += sizeof (item))) caddr_t sp; int foo; short int bar; unsigned char biff; PUSH(sp, foo); PUSH(sp, bar); PUSH(sp, biff); ... The poster you quoted was probably referring to something like (type) complicated_expression++ = item; where it's undesirable to realize the complicated_expression twice.