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 #175762 is a reply to message #175742] Sun, 23 October 2011 17:00 Go to previous messageGo to previous message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma:
Senior Member
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

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
[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: Thu Nov 28 12:37:53 GMT 2024

Total time taken to generate the page: 0.05382 seconds