On Mon, 16 May 2005, Dave Dunfield wrote:
There's one
extra local variable (char *t) which is a pointer: hardly
expensive by any metric. If you prefer, move the i initializer inside the
for loop construct. Same difference.
The loop uses the same number of conditionals as
any other example so far
(including yours, which doesn't work ;)
I guess you missed my original solution - look back a few messages,
it uses only one conditional, and only one local variable, has no
superflous assignments, nor goto's.
Saw it after I posted my "masterpiece".
The "clever" one in my last message was an
illustation, not my
solution.
Still clever ;)
Your analysis
somewhat (misses the point|is non-sequitur). The unary
construct is the entire reason this works.
It still stuffs an address into a conditional - it works, but it's
not pretty, nowhere near the goal of "structured" (remember structured
... this is a song about structured) and not something I would ever
consider using in production code.
At least I wasn't jumping into a for loop with a goto ;)
Perhaps this is
an issue of precedence and compiler implementation, but
the way it works (at least under gcc) is as I suspected, which is that
counter i gets incremented after first being added to aryp. So it in fact
iterates the entire array from start to end.
* is higher precedence than '+' (K&R page 49 - I know this from memory -
scary). If your compiler does the '+' first, it's broken.
You know, you're right. gcc version 2.95.3. But it worked. I just
enclosed the expression in proper parentheses and it of course works.
Don't know why I wasn't before getting output:
1,3,5,7,9
You had card
punches? We had to cut holes into ours with exacto knives.
Actually, when I last visited the Your university museum, the Curator
showed me some "manual" card punches - little steel blocks with holes
and a pin punch!
I've got something similar made by IBM. It's a little plastic tray with a
stylus punch. You put the card in the tray and then punch out the holes
you want. Fun!
(And conveniently back on-topic...)
--
Sellam Ismail Vintage Computer Festival
------------------------------------------------------------------------------
International Man of Intrigue and Danger
http://www.vintage.org
[ Old computing resources for business || Buy/Sell/Trade Vintage Computers ]
[ and academia at
www.VintageTech.com || at
http://marketplace.vintage.org ]