comp.lang.c
[Top] [All Lists]

Re: acceptable use of goto?

Subject: Re: acceptable use of goto?
From: Morris Dovey
Date: Wed, 26 Mar 2008 18:14:20 -0500
Newsgroups: comp.lang.c

Richard wrote:
> 
> Morris Dovey <mrdovey@xxxxxxxx> writes:
> 
> > Richard wrote:
> >
> >> Asm is totally platform specific and Off Topic.
> >
> > Of course it is - that's why it was made available elsewhere,
> > with only a link here.
> >
> >> Sorry, but you fail the design admission test.
> >
> > Then it's a good thing I don't do that for a living. :-)
> >
> >> And please dont snip the code in question:
> >>
> >> bens code: does not crash or exhibit UDB
> >>
> >> ,----
> >> | void print_int_array(int *array, size_t arraylen)
> >> | {
> >> |     putchar('(');
> >> |     for (size_t i = 0; i < arraylen; i++)
> >> |         printf("%s%d", (i ? ", " : ""), array[i]);
> >> |     putchar(')');
> >> | }
> >> `----
> >>
> >> your code which can:
> >>
> >> ,----
> >> | void print_int_array(int *array, size_t arraylen)
> >> | {  putchar('(');
> >> |    do printf("%d%s",*array++,--arraylen?", ":")\n");
> >> |       while (arraylen);
> >> | }
> >> `----
> >
> > And the (smaller) case you chose ignore/not quote:
> 
> I didnt see that. All my comments were based on your original submission
> which you then defended by saying/insinuating you had the checks done
> externally.

In nearly all of the work I did, removal of _all_ avoidable
overhead was crucial. I used printf() here because it seemed
counter-productive to use faster and smaller code to pump out an
integer value, but it's been a very long time since I've used it
in production code - eight years, to be exact, and that version
of printf() was stripped to just the subset of conversions used
in that project's code.

I don't have any difficulty visualizing scenarios where
performance might not be such an issue, nor where a couple of
extra bytes here and there isn't a problem. I offer for your
consideration that there is an entire spectrum of environments -
and that, at one end of the spectrum, making code idiot-proof
takes a back seat to making the code fit into available memory or
meet hardware timing requirements.

> >    void print_int_array(int *array,size_t arraylen)
> >    {  if (arraylen > 0)
> >       {  putchar('(');
> >          do printf("%d%s",*array++,--arraylen?", ":")\n");
> >             while (arraylen);
> >       }
> >    }
> >
> >> To be honest I am surprised you are defending your code.
> >
> > I wasn't, and have enough of it running around the world (and
> > above it) to not feel the need to defend it. Rather, the
> > intention was to share something I thought you might find
> > interesting. A silly error on my part.
> 
> I am unsure as to which bit of your original code is interesting?
> Seriously, I can see no reason for it and it would have failed any code
> reviews that I have been part of in the past. I dont mean this to insult
> you, but to point out that NOT doing the zero check was silly and did
> pretty much nothing in terms of efficiency one way or another.

What I found interesting was that the code _with_ the if
statement compiled to fewer machine instructions than the code
_without_ the test (for my particular toolchain and for my
particular environment) which struck me as counter-intuitive. I
thought /you/ might find it interesting because it strengthened
/your/ case.

> Think of it as debugging "visually" as you were so supportive of a few
> days earlier :-;

My views on that aren't likely to change much - not because I
have anything against debuggers, but rather because they don't
usually fill my needs. When I last actually _needed_ a debugger,
I ran the code inside a room-sized ICE (with an absolutely
obscene price tag) and found a handful of circuit errors in the
SOC.

-- 
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy