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

Home » Imported messages » comp.lang.php » Operator precedence
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Operator precedence [message #185056 is a reply to message #185052] Tue, 25 February 2014 04:59 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 2/24/2014 10:41 PM, Richard Damon wrote:
> On 2/24/14, 7:00 AM, Jerry Stuckle wrote:
>
>> What language gives every possible way for you to screw up your
>> programming?
>>
>> If you want to find out how some screwed-up code works in ANY language,
>> you try it and find out.
>>
>
> Herein lies the path to madness.
>
> Take the following C code
>
> #include <stdio.h>
>
> int main() {
> int i = 4;
> i = ++i + i++;
> printf("%i\n", i);
> return 0;
> }
>
> Question, you want to find out what this is supposed to do. By your
> statement, you run it on a system. The problem is that the answer you
> get is only valid for THAT system, and possible for that EXACT piece of
> code.
>

No, it shows how it works with THIS compiler. Not even this system - a
different compiler may give different results. But then the same is
true for ANY compiler.

But then all I claimed was to try it and see how it works for THIS system.

For instance, what is the output of:

int main() {
int i = 1;
int j = i << 32;
printf("%d\n", j);
?>

> The REAL answer is you compare the code to the formal specification of
> the language, and you get the answer.
>

IF you have the formal specification available, and are able to
understand it.

> Too many people use your answer, and then complain because they get a
> different answer on another machine, or in different circumstances, and
> then complain that the compiler is "broken", when the real answer is
> that THEIR program was the one that was broken.
>
> (For those not familiar with C, the answer in this case is that the
> program has performed "undefined behavior" by modifying i twice without
> a sequence point, and thus *ANY* resultant behavior is acceptable.
>

That is true - and you will not find your example in the ANSI C spec -
which is why its output is not defined.

> Here is a question, does PHP's documentation promise how the equivalent
> PHP statement will execute?
>
> ...

You tell me.

>
>
>>> The assignment operators in PHP have, in effect, different precedences
>>> on the left and the right (a feature that some languages flaunt) but
>>> that is not common and certainly not part of what I'd call basic
>>> knowledge. The documentation gives one example of this peculiarity, but
>>> that does not clear the matter up conclusively. For example, in some
>>> languages permit assignment to the result of a conditional expression,
>>> but I think it's hard to tell from the documentation what these two do:
>>>
>>> $bool ? $a : $b = 42;
>>> ($bool ? $a : $b) = 42;
>>>
>>
>> Show me what language provides you with examples of every possible
>> combination of operators and expressions.
>
> Read the C Grammer definition. It precisely describes how ANY expression
> is to be parsed.
>
> It does give the compiler freedom to choose the order to execute the
> parse tree, so things without inherent order have no promise of order,
> but this is made explicit.
>

I have - many times while working on updating C courses. So much, in
fact, that I completely wore out the ANSI spec I had (and which cost me
a bunch of $$$).

The spec specifies the order that operators are evaluated. It does NOT
specify the order in which operands are evaluated. That is why your
example has undefined results - the spec does not define what should happen.

>
>>
>>> The operator precedence table suggests that both mean the same thing,
>>> but they don't. I don't think the meaning of either is easily
>>> determined from the documentation.
>>>
>>> <snip>
>>>
>>
>> So you try it out, as you do in any language. But just because you can
>> come up with some weird combination of operators which isn't listed in
>> the doc does not mean the language is not rigorously defined.
>> with
>> But it does mean you are trolling.
>>
>
> Rigorously defined would mean "precisely or exactly defined", which,
> yes, does say that if you can come up with a "weird" combination, that
> is not documented as to what is to happen, the definition is not
> rigorous. A Formal definition, will be complete, as that is part of
> being formal.
>

PHP is defined as rigorously as other languages. Just in a more
reader-friendly way. (It took me a long time to figure out my way
through the ANSI C spec - and even longer for SQL).

But then since you seem to hate PHP so much, I suggest you just find
another language more to your liking and stop wasting people's time in a
PHP newsgroup. More trolls we don't need.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
[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
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: Correlating curl resources to some other object.
Next Topic: Experienced Web designer required
Goto Forum:
  

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

Current Time: Thu May 09 20:14:35 GMT 2024

Total time taken to generate the page: 0.05034 seconds