Prev: System Calls
Next: Warning to newbies
From: Eric Chomko on 17 Mar 2010 13:51 On Mar 17, 9:33 am, Ahem A Rivet's Shot <ste...(a)eircom.net> wrote: > On Wed, 17 Mar 2010 07:03:43 -0500 > > jmfbahciv <jmfbahciv(a)aol> wrote: > > Jonathan de Boyne Pollard wrote: > > > Such edicts make one want to write code in the form > > > > x /* The variable x */ > > > = /* is assigned */ > > > x /* its value * / > > > + /* plus * / > > > 2 /* one */ > > > ; /* . */ > > > And would make all tapes spill over to two magtapes. > > > Fortunately, your code would produce many detected errors. > > Nope that's perfectly valid C code - provided that x is declared in > scope. > Isn't "in scope" redundant here? I mean scope only applies to binding time, no? Locals vs. globals vs. non-locals which are not global, etc. But I agree the code is fine from the stand point of the compiler.
From: Keith Thompson on 17 Mar 2010 14:50 Eric Chomko <pne.chomko(a)comcast.net> writes: > On Mar 17, 9:33 am, Ahem A Rivet's Shot <ste...(a)eircom.net> wrote: >> On Wed, 17 Mar 2010 07:03:43 -0500 >> >> jmfbahciv <jmfbahciv(a)aol> wrote: >> > Jonathan de Boyne Pollard wrote: >> > > Such edicts make one want to write code in the form >> >> > > x /* The variable x */ >> > > = /* is assigned */ >> > > x /* its value * / >> > > + /* plus * / >> > > 2 /* one */ >> > > ; /* . */ >> >> > And would make all tapes spill over to two magtapes. >> >> > Fortunately, your code would produce many detected errors. >> >> Nope that's perfectly valid C code - provided that x is declared in >> scope. >> > > Isn't "in scope" redundant here? I mean scope only applies to binding > time, no? Locals vs. globals vs. non-locals which are not global, > etc. But I agree the code is fine from the stand point of the > compiler. Agreed. But note that the "its value" and "plus" comments aren't properly terminated, so the "/*" on the "its value" line introduces a comment that isn't terminated until the "*/" on the "one" line. The net result is "x = x;" -- Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Scott Lurndal on 17 Mar 2010 14:58 Eric Chomko <pne.chomko(a)comcast.net> writes: >On Mar 17, 9:33=A0am, Ahem A Rivet's Shot <ste...(a)eircom.net> wrote: >> On Wed, 17 Mar 2010 07:03:43 -0500 >> >> jmfbahciv <jmfbahciv(a)aol> wrote: >> > Jonathan de Boyne Pollard wrote: >> > > Such edicts make one want to write code in the form >> >> > > =A0 =A0 x =A0/* The variable x */ >> > > =A0 =A0 =3D =A0/* is assigned */ >> > > =A0 =A0 x =A0/* its value * / >> > > =A0 =A0 + =A0/* plus * / >> > > =A0 =A0 2 =A0/* one */ >> > > =A0 =A0 ; =A0 /* . */ >> >> > And would make all tapes spill over to two magtapes. >> >> > Fortunately, your code would produce many detected errors. >> >> =A0 =A0 =A0 =A0 Nope that's perfectly valid C code - provided that x is d= >eclared in >> scope. >> > >Isn't "in scope" redundant here? I mean scope only applies to binding >time, no? Locals vs. globals vs. non-locals which are not global, >etc. But I agree the code is fine from the stand point of the >compiler. except for the two occurances of '* /' instead of '*/'. scott
From: Jonathan de Boyne Pollard on 18 Mar 2010 02:46 > > > Agreed. But note that the "its value" and "plus" comments aren't > properly terminated, so the "/*" on the "its value" line introduces a > comment that isn't terminated until the "*/" on the "one" line. The > net result is "x = x;" > Hooray! At last! Well spotted. I've been waiting to see how long it took and how many would do so. So not only does the mandatory comment on every line not match the apparent code, but the apparent code isn't the actual code, as a direct consequence of the mandatory comments. I'm assuming that M. Shanahan either spotted this too, or would have done so.
From: Jonathan de Boyne Pollard on 18 Mar 2010 02:48
> >> >> Such edicts make one want to write code in the form >> > x /* The variable x */ > = /* is assigned */ > x /* its value * / > + /* plus * / > 2 /* two */ > ; /* . */ > > Correction applied. HTH. > As you now know, you got the correction wrong. This was a deliberately subtle point. The discrepancy in the mandatory comment prose caused you to overlook another error. I deliberately made it a well-known and fairly basic C programming error that most of the people participating in this thread from comp.lang.c should all be familiar with, and regularly leap upon in posted code, moreover. |