Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!amdcad!ames!haven!ncifcrf!nlm-mcs!adm!smoke!gwyn From: gwyn@smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: cast changes meaning of auto-increment? Keywords: cast, ++ Message-ID: <8484@smoke.ARPA> Date: 13 Sep 88 13:56:28 GMT References: <901@mina.liu.se> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 19 In article <901@mina.liu.se> mikpe@mina.liu.se (Mikael Pettersson) writes: > register char *cp, *oldcp; > oldcp = cp = (char *)&i; > printf("i == %d, ", *(int *)cp++); /* should print `27' */ > printf("and cp increased by %d\n", cp-oldcp); /* 4 or 1 ? */ >My question is: what should be printed by the second printf, 4 or 1? 1, of course. It's the difference between the old (char *) and an incremented-by-one (char *). >Since a cast doesn't produce an lvalue, ... This has nothing to do with lvalues. The indirection operator, the cast operator, and ++ are right-associative at the same level of precedence in the C grammar. The ++ operates on cp before the other operators in this example. (However, the incremented value is not stored into cp until after the original value of cp is used, by the very definition of the post-increment operator.)