FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » simple session question
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: simple session question [message #175769 is a reply to message #175762] Sun, 23 October 2011 19:28 Go to previous messageGo to previous message
Richard Damon is currently offline  Richard Damon
Messages: 58
Registered: August 2011
Karma:
Member
On 10/23/11 1:00 PM, Thomas Mlynarczyk wrote:
> Richard Damon schrieb:
>
>> The issue is C is that there is a general rule (to allow
>> optimizations) that defines the behavior to be undefined if an
>> expression causes a variable to be written to twice, or have a read
>> from and write to (where the read from is not needed to determine the
>> value to write to) without an intervening sequence point, like the end
>> of an expression.
>
> So basically, it boils down to "programmer" vs. "compiler": The
> programmer would like to have everything defined clearly, because
> anything "undefined" simply means (s)he cannot use that construct. The
> compiler, on the other hand, can work the better, the fewer restrictions
> there are, and thus "welcomes" anything left undefined. And C focuses
> more on the compiler, while PHP focuses more on the programmer.
>
>> The statement x = x++; has two different writes to x, so we meet the
>> requirement for undefined behavior. Not also that C does not limit
>> when the ++ part happens, only that this side effect will finish by
>> the next sequence point.
>
> So in C, the statement x = x++ is regarded "as a whole" and the compiler
> can do anything with it as long as certain constraints are observed,
> while PHP, being a higher level language than C, must have all the tiny
> internal steps well defined.
>
>> Part of the problem with this example is that it is a bit to simple,
>> and that simplicity hides some of the issues. Let us make the
>> expression just slightly more complicated to make it cleared. Let us
>> use x = 5*x++;
>
> If I have understood you correctly, this would be
>
> In PHP:
> [1] $tmp = $x;
> [2] $x = $x + 1;
> [3] $tmp = 5 * $tmp;
> [4] $x = $tmp;
> In exactly that order (or maybe [2] and [3] swapped as it would make no
> difference).
>
> In C:
> [TODO] RHS = 5 * (value of x before increment)
> [TODO] increment x
> [TODO] LHS = RHS
> With the only restriction on the order being that the third item must
> necessarily come after the first and it's up to the compiler to choose.
>
> Greetings,
> Thomas
>

Actually, both have the same basic steps (in principle)

(1) temp1 = x
(2) temp2 = x
(3) x = temp2 + 1
(4) temp3 = 5 * temp2
(5) x = temp3

(1 & 2 may be redundant and combined)
2,3 are the x++, 1,4,5 is the x = 5*x
by necessity we need the following order (can't use a value before it is
available)

1 -> 4 -> 5
2 -> 3
and by the definition of x++, 1 -> 3

PHP appears to define the order to be

1,2 -> 3 -> 4 -> 5

which means the increment of x is done tied to the fetching of the value
of x.

C places no additional restrictions on the order of the parts.

In particular, 3 can come before or after 5, and if 3 is after 5, 2 can
be before or after 5.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: session cookie: client side
Next Topic: by get this format my explode file name like this through php
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 06:01:53 GMT 2024

Total time taken to generate the page: 0.04902 seconds