WAY WAY WAY WAY OT Re: 'goto" gone from computer languages or is it!
Vintage Computer Festival
vcf at siconic.com
Mon May 16 18:40:44 CDT 2005
On Mon, 16 May 2005, Dave Dunfield wrote:
> >I trump thee collectively:
> >
> >void print_arg(int *aryp, size_t n)
> >{
> >
> > char *t="%u,";
> > int i=0;
> >
> > for (;(i==n-1 ? t="%u" : i<n);) printf(t, *aryp + i++);
> >
> > putchar('\n');
> >
> >}
> >
> >A little ugly (the compiler complains about the type mismatch in the unary
> >expression) but otherwise it works without caveats (that I know of ;)
> >
> >I suspect someone might bum it down further...no more precious time to
> >expend on this useless pursuit ;)
>
> I'm a little confused about the definition of "trump" when used in
> this case:
>
> - You have returned to an excess of local variables, and the
> extra assignment - although you have used a (more expensive)
> conditional to defer it until the last iteration.
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.
> - You have returned to TWO conditionals, although you have
> creatively moved them both into the for statement.
The loop uses the same number of conditionals as any other example so far
(including yours, which doesn't work ;)
> - In the last iteration of the loop you are stuffing the address
> value of the constant string "%u" into the for conditional
> (granted in any reasonable implementation this will be non-zero
> and will evaluate to TRUE, however it seems a bit odd and not
> completely necessary to the logic of the program).
Your analysis somewhat (misses the point|is non-sequitur). The unary
construct is the entire reason this works.
> - You are reading only the first element of the array, although
> you are adding an increasing offset to it for each iteration of
> the loop.
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.
> This really is getting silly.
Yes, but at least we're not talking about cars or guns.
> So... Seen any good old computers lately?
Thousands.
> How about them Altairs - ain't they something?
Over-rated.
> When I was a gaffer, we had to carry our card decks
> uphill both ways to the card punch!
You had card punches? We had to cut holes into ours with exacto knives.
--
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 ]
More information about the cctalk
mailing list