Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.lang.c Subject: Re: pointer increment Message-ID: <3030@solo9.cs.vu.nl> Date: 21 Aug 89 18:16:27 GMT References: <484@eagle.wesleyan.edu> <829@ruso.UUCP> <3003@solo1.cs.vu.nl> <834@ruso.UUCP> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 62 wolfgang@ruso.UUCP (Wolfgang Deifel) writes: \maart@cs.vu.nl (Maarten Litmaath) writes: \> I wrote: \>\... \>\ ((char*)ptr)++ ; \>\Now ptr becomes 1 ( = sizeof(char) ) more. \ \>Aaaaaaarrrrrgghh! Wayne Throop's Sacred Mission isn't finished yet... \ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \ \ Thank god that you are born as expert... There's no need to feel p*ssed off, Wolfgang; I wasn't trying to insult you or something. Of course I should have added a detailed explanation, but I figured someone else would supply that. Having read your article I remembered Wayne Throop's 1985 (1986?) crusade against "the vile heresy which claimeth that ((char*)ptr)++ will increment ptr" (free after Henry Spencer's Ten Commandments for C Programmers). Allright. A compiler that allows the abovementioned construct is wrong for two reasons: 1) It allows the `++' operator to be applied to an Rvalue expression; only Lvalue expressions may be operand of an increment operator, e.g. x++ a[i]++ This isn't so strange: x++ is equivalent to x = x + 1 which doesn't make sense for arbitrary (Rvalue) expressions. 2) It increments the wrong variable; a cast is equivalent to an assignment to an invisible temporary variable (with the usual restrictions and conversions): foo x; ... (bar) x ... becomes foo x; bar cast_tmp; /* `invisible' temp variable */ ... (cast_tmp = x) ... If we write the latter expression as (cast_tmp = x, cast_tmp) it's clearly `cast_tmp' which should be incremented (if a `++' operator is appended), were this possible at all; definitely NOT `x'. -- "rot H - dD/dt = J, div D = rho, div B = 0, |Maarten Litmaath @ VU Amsterdam: rot E + dB/dt = 0" and there was light. |maart@cs.vu.nl, mcvax!botter!maart