Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Mac Misc > Re: awka on Mac...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 7 Topic 6039 of 6369
Post > Topic >>

Re: awka on Mac OS X 10.4.11 [Intel]

by Janis <janis_papanagnou@[EMAIL PROTECTED] > Apr 24, 2008 at 06:28 AM

On 24 Apr., 14:46, Robert Peirce <b...@[EMAIL PROTECTED]
>
wrote:
> In article <funkla$p3...@[EMAIL PROTECTED]
>,
> =A0Janis Papanagnou <Janis_Papanag...@[EMAIL PROTECTED]
> wrote:
>
> > Robert Peirce wrote:
>
> > > Frankly, it never occurred to me that these would be different. =A0I
s=
till
> > > have trouble figuring out the logic behind the line that produced
28. =
=A0
> > > 25 made sense, but not 28.
>
> > Why? If b was 13 and is pre-incremented before the rest of the
> > expression is evaluated then you have 14 + 14 =3D 28.
>
> > =A0 =A0print b =A0 =A0 =A0 =A0 =A0 =A0# 13
> > =A0 =A0print b +=3D ++b
> > =A0 =A0print b
>
> I didn't say I couldn't figure it out. =A0I said I had trouble figuring
it=

> out. =A0It is interesting that some awks produce 25 while others produce
> 28. =A0This is clearly some pretty tricky C coding that is not well
> understood by everybody.

Tricky? I'd rather call that "obfuscating coding" (if not "random
coding" or "unreliable coding"). Coding that way has not so much
to do with "understanding" such constructs. It's a well known class
of constructs that is called Side Effects. Any language that allows
constructs with a syntax that is "lexically ambiguous" has choices
to define the semantics in some way, or leave it explicitly as
"undefined behaviour". The C language definition has concepts of
sequencing points to explain behaviour of certain construct like
this one; though still not all lexically possible constructs are
covered, AFAIK.[*] It would be interesting to know whether awk
has similar rules or left the semantics in that case unspecified.

Janis

[partly off-topic...]

[*] Is evaluation of the following in the C standard defined in a
deterministic way...?  { x=3Da; y=3Df(x++, ++x); }

C version:
  #include<stdio.h>
  int f(int p,int q) { return p*q; }
  int main (void)
  { int x, y;
    x=3D5; y=3Df(x++, ++x); printf ("%d\n", y);
    x=3D5; y=3Df(++x, x++); printf ("%d\n", y);
    return 0;
  }
  // Output:
  36
  35

Awk version (MKS):
  function f(p,q) { return p*q }
  BEGIN {
    x=3D5; y=3Df(x++, ++x); printf ("%d\n", y);
    x=3D5; y=3Df(++x, x++); printf ("%d\n", y);
  }
  # Output:
  35
  36
 




 7 Posts in Topic:
awka on Mac OS X 10.4.11 [Intel]
Robert Peirce <bob@[EM  2008-04-23 11:42:55 
Re: awka on Mac OS X 10.4.11 [Intel]
Janis <janis_papanagno  2008-04-23 05:48:55 
Re: awka on Mac OS X 10.4.11 [Intel]
Thomas Weidenfeller <n  2008-04-23 15:48:54 
Re: awka on Mac OS X 10.4.11 [Intel]
Robert Peirce <bob@[EM  2008-04-23 14:55:05 
Re: awka on Mac OS X 10.4.11 [Intel]
Robert Peirce <bob@[EM  2008-04-24 12:46:46 
Re: awka on Mac OS X 10.4.11 [Intel]
Janis <janis_papanagno  2008-04-24 06:28:43 
Re: awka on Mac OS X 10.4.11 [Intel]
pk <pk@[EMAIL PROTECTE  2008-04-24 15:42:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 12:07:07 CDT 2008.