Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!rpi!crdgw1!camelback!volpe From: volpe@camelback.crd.ge.com (Christopher R Volpe) Newsgroups: comp.lang.c Subject: Re: Assignment Ops and Side Effects Message-ID: <18324@crdgw1.crd.ge.com> Date: 8 Apr 91 13:14:50 GMT References: <1991Apr3.173046.2367@mccc.edu> <1991Apr4.202314.961@csrd.uiuc.edu> <11805@dog.ee.lbl.gov> <1991Apr5.012413.24124@athena.mit.edu> <1991Apr5.234636.22610@csrd.uiuc.edu> Sender: news@crdgw1.crd.ge.com Reply-To: volpe@camelback.crd.ge.com (Christopher R Volpe) Lines: 26 In article <1991Apr5.234636.22610@csrd.uiuc.edu>, bliss@sp64.csrd.uiuc.edu (Brian Bliss) writes: |>> For the compiler that thinks that sizeof(c += 1) is sizeof(int), |>> I wonder what it thinks about sizeof(c = 1) or sizeof(c = 1.0) ? |>(c is a char) |> |>The compiler is Sun 4.0's cc, and indeed, it returns 1 for both cases. |>So indeed it is the assignment that is responsible for coercing |>the result back to char type. |> |>bb Could someone explain to me why sizeof(c=1) is 1 and not (typically) 4?? The result of the assignment operator is not an l-value, and thus undergoes the integral promotions. The result of "c=1" in an expression context should be promoted to int. For example, for an unprototyped function f, f(c=1) assigns 1 to the character c, and then passes the INTEGER 1 to f. Similarly, sizeof(c=1) should see that its operand is a non-lvalue value of type char (the value is not evaluated) and should thus be promoted to int. (For sizeof(c), c is an lvalue and does not undergo promotion since it is an operand of sizeof. (Section 3.2.2.1 paragraph 2)) ================== Chris Volpe G.E. Corporate R&D volpecr@crd.ge.com