Searching \ for '[EE]:GOTO' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=goto
Search entire site for: 'GOTO'.

Exact match. Not showing close matches.
PICList Thread
'[EE]:GOTO'
2000\09\12@113120 by Peter Schultz

flavicon
face
Hi Guys,
I need your opinion in the case of battle with the software QA department.
They are saying GOTO in C not acceptable.
I checked the books, some of them said no, some of them saying in some
places there is a use for GOTO.
My practice said, when writing code for PIC especially fast operation with
nested loops
( like decoding noise RF Manchester transmission at 100 kbit/s ) GOTO is
absolutely necessary.
Any thought on that issue?
Peter Schultz
Minimed Inc.
12744 San Fernando Road,
Sylmar, CA 91342
Phone: (818) 362-2358x3837
Pager:  (818) 589-3148
E-mail: spam_OUTPeterSTakeThisOuTspamminimed.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use .....listservKILLspamspam@spam@mitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@113943 by Andrew Kunz

flavicon
face
ALWAYS use the right tool for the job.  If that tool happens to be GOTO, so be
it.

Personally, I try to use goto's in exception handling only.  Unless it happens
to be the right tool for the job somewhere else. :-)

Andy










Peter Schultz <PeterSspamKILLspamMINIMED.COM> on 09/12/2000 11:25:48 AM

Please respond to pic microcontroller discussion list <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>








To:      EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU

cc:      (bcc: Andrew Kunz/TDI_NOTES)



Subject: [EE]:GOTO








Hi Guys,
I need your opinion in the case of battle with the software QA department.
They are saying GOTO in C not acceptable.
I checked the books, some of them said no, some of them saying in some
places there is a use for GOTO.
My practice said, when writing code for PIC especially fast operation with
nested loops
( like decoding noise RF Manchester transmission at 100 kbit/s ) GOTO is
absolutely necessary.
Any thought on that issue?
Peter Schultz
Minimed Inc.
12744 San Fernando Road,
Sylmar, CA 91342
Phone: (818) 362-2358x3837
Pager:  (818) 589-3148
E-mail: PeterSspamspam_OUTminimed.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use @spam@listservKILLspamspammitvma.mit.edu?body=SET%20PICList%20DIGEST

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use KILLspamlistservKILLspamspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@114147 by Phillip Vogel

flavicon
face
Hey, you can always program around having to use GOTO, but often that will
lead to a lot of extra code, which is not necessarily readable. Besides, if
you are comfortable with the GOTO, and there is nothing 'unsafe' about it,
then why would you want to program around it?

Actually, if the GOTOs inside nested loops are a problem, you might try
unrolling the loops to get (a little) extra speed.

Just $.02 worth of anti-establishment sentiment...

P.

Peter Schultz wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@115431 by Dipperstein, Michael

face picon face
The answer depends upon the hat you're wearing.  Some computer science types
have made careers by studying gotos.  They will tell you that anything you can
do in C with a goto, you can do without a goto.  Being computer science types
they will tell you that you need infinite memory.

There are cases, none of which come to mind right now, were a goto can allow you
to reduce code size or stack consumption.  A few months back, I ran into a case
on a PIC16F877, where I had to remove a function call, because the 8 word stack
had potential to overflow.  I can't remember what the case was, but I had the
option to either duplicate the code in the function, or use a goto.  I wasn't
hurting for ROM, so I chose the duplicate code option.

If I didn't have the ROM, then a goto would have been absolutely necessary.

Next time you might try to hide the goto from the SQA guys by burring it in a C
or assembly macro.  What they don't know won't hurt them.

-Mike


{Original Message removed}

2000\09\12@120243 by Andrew Kunz

flavicon
face
>had potential to overflow.  I can't remember what the case was, but I had the
>option to either duplicate the code in the function, or use a goto.  I wasn't
>hurting for ROM, so I chose the duplicate code option.

This approach if far more wrong than using a goto.  If you need to change the
function, you now must change it twice.  At least with a goto, you know it's got
to be there because you put a label on it.  If you duplicated the code, the next
guy has no idea you duplicated it because there isn't (aside from comments,
which are usually wrong) anything to warn him.

Andy

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use RemoveMElistservspamTakeThisOuTmitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@120647 by M. Adam Davis

flavicon
face
Strictly speaking, the only place GOTO is acceptable in C is in an error routine
(ie, if broke goto someplace safe, parse the error, exit the routine).  This
prevents the processor from changing state (stack, memory, etc) so that your
error routine can have a full view of what state the processor was in when the
error occured.

If using goto speeds up your routine significantly compared to typical loops and
control structures, then chances are your compiler doesn't do very good
optimization (or you aren't using the loops and control structures in an
efficient manner).  If that's the case, then tell QA that you are using Goto to
get around compiler limitations (and get them to fund a good compiler).  A good
compiler, compiling good C code without Goto should be as efficient as code with
Gotos in it.

If need be, program the critical loop in C (with or without goto), take the
assembly output, put it into the C program as inline assembly and hand optimize
it.  They can't complain about using goto in assembly.

It sounds like you are writing a routine which needs to be fast and efficient in
a high level language (C) where it might be more appropiate to use a lower level
language (assembly).  C is designed as a high level language which discourages
the use of Goto, if I find that I cannot write a program without the use of
goto, then C is not the correct language to use.  Sure, I could program it in C
with Goto, but the code becomes less portable, more difficult to maintain, and
becomes prone to the dreaded spaghetti code syndrome.

-Adam

Peter Schultz wrote:
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use RemoveMElistservEraseMEspamEraseMEmitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@121100 by Stephen B Webb

flavicon
face
> My practice said, when writing code for PIC especially fast operation with
> nested loops
> ( like decoding noise RF Manchester transmission at 100 kbit/s ) GOTO is
> absolutely necessary.

I think that programming for the PIC and programming for a large general
purpose computer are different enough to warrant different rules.  As
someone mentioned before, the stack limit could be reason to justify a
goto.

I have a program that I am planning on migrating to a 2-deep stack PIC,
and I can assure you that I use gotos without feeling bad about it.

So, if they are trying to apply a general rule to a "special" (i.e. pic ==
special) case, maybe they could reconsider.

-Steve

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use RemoveMElistservspam_OUTspamKILLspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@122119 by Dipperstein, Michael

face picon face
>>had potential to overflow.  I can't remember what the case was, but I had the
>>option to either duplicate the code in the function, or use a goto.  I wasn't
>>hurting for ROM, so I chose the duplicate code option.

>This approach if far more wrong than using a goto.  If you need to change the
>function, you now must change it twice.  At least with a goto, you know it's
got
>to be there because you put a label on it.  If you duplicated the code, the
next
>guy has no idea you duplicated it because there isn't (aside from comments,
>which are usually wrong) anything to warn him.

The code was written as a single macro, which appears in multiple portions of
the code.  With PICs I find myself writing a lot more macros than I do for a
CPU.  Besides, I never make mistakes and all my code has the ability to self
adapt to future requirements that may be placed on it :-)

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use RemoveMElistservTakeThisOuTspamspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@130759 by Bob Ammerman

picon face
----- Original Message -----
From: M. Adam Davis <EraseMEadavisspamspamspamBeGoneUBASICS.COM>
To: <RemoveMEPICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Tuesday, September 12, 2000 12:05 PM
Subject: Re: [EE]:GOTO


> Strictly speaking, the only place GOTO is acceptable in C is in an error
routine
> (ie, if broke goto someplace safe, parse the error, exit the routine).
This
> prevents the processor from changing state (stack, memory, etc) so that
your
> error routine can have a full view of what state the processor was in when
the
> error occured.
>
> If using goto speeds up your routine significantly compared to typical
loops and
> control structures, then chances are your compiler doesn't do very good
> optimization (or you aren't using the loops and control structures in an
> efficient manner).  If that's the case, then tell QA that you are using
Goto to
> get around compiler limitations (and get them to fund a good compiler).  A
good
> compiler, compiling good C code without Goto should be as efficient as
code with
> Gotos in it.

Not necessarily true!

> If need be, program the critical loop in C (with or without goto), take
the
> assembly output, put it into the C program as inline assembly and hand
optimize
> it.  They can't complain about using goto in assembly.

ROTFL

> It sounds like you are writing a routine which needs to be fast and
efficient in
> a high level language (C) where it might be more appropiate to use a lower
level
> language (assembly).  C is designed as a high level language which
discourages
> the use of Goto, if I find that I cannot write a program without the use
of
> goto, then C is not the correct language to use.  Sure, I could program it
in C
> with Goto, but the code becomes less portable, more difficult to maintain,
and
> becomes prone to the dreaded spaghetti code syndrome.

Very good point

> -Adam
>
> Peter Schultz wrote:
> >
> > Hi Guys,
> > I need your opinion in the case of battle with the software QA
department.
> > They are saying GOTO in C not acceptable.
> > I checked the books, some of them said no, some of them saying in some
> > places there is a use for GOTO.
> > My practice said, when writing code for PIC especially fast operation
with
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use EraseMElistservspamEraseMEmitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@143016 by Olin Lathrop

flavicon
face
> I need your opinion in the case of battle with the software QA department.
> They are saying GOTO in C not acceptable.
> I checked the books, some of them said no, some of them saying in some
> places there is a use for GOTO.
> My practice said, when writing code for PIC especially fast operation with
> nested loops
> ( like decoding noise RF Manchester transmission at 100 kbit/s ) GOTO is
> absolutely necessary.
> Any thought on that issue?

Sounds like someone is losing sight of the real goal here.  The original
motivation for not using GOTOs was that block stuctured code is easier to
follow and to maintain.  All other things being equal, this is true.  But
there are many other factors that contribute to making code easy to follow
and maintain, with good block and end of line comments being top of the
list.  Perfect block structuring will never make up for poor design and
documentation.  I believe there are also cases where properly used GOTOs can
even enhance understandability.  Although it is theoretically possible, not
all program flows are best expressed in block structure form.  There are
also definite execution speed advantages in some special circumstances,
though that is not an issue except in the relatively rare code that is
speed-critical.

I use block structures as much as possible in high level language code, but
do use GOTOs when I think it simplifies the code.  Of course any label that
is a target of a goto should have a good comment associated with it that
explains why execution might get here other than by falling thru.

In short, I think your QA people are being small minded paper pushing weenies.
They are probably just following rules that they don't understand the reasons
behind.  This reminds my why I don't want to be an employee at a large
company.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, @spam@olin@spam@spamspam_OUTcognivis.com, http://www.cognivis.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use spamBeGonelistservspamKILLspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@143022 by Olin Lathrop

flavicon
face
> >had potential to overflow.  I can't remember what the case was, but I had
the
> >option to either duplicate the code in the function, or use a goto.  I
wasn't
> >hurting for ROM, so I chose the duplicate code option.
>
> This approach if far more wrong than using a goto.  If you need to change
the
> function, you now must change it twice.  At least with a goto, you know
it's got
> to be there because you put a label on it.  If you duplicated the code,
the next
> guy has no idea you duplicated it because there isn't (aside from
comments,
> which are usually wrong) anything to warn him.

I agree with the rule of there should only be one piece of source code for
any one function.  You can still have this and replicate the code by using a
macro.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, .....olinspam_OUTspamcognivis.com, http://www.cognivis.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use TakeThisOuTlistserv.....spamTakeThisOuTmitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@152508 by Harold M Hallikainen

picon face
       Though use of a macro or an include file would allow this multiple
insertion of the code without the insertions diverging. The problem of
two copies of code and not knowing which is right is like the person with
two watches never knows what time it is, but the person with one watch
does. On the watch problem... If we average all the times on all the
clocks in a time zone, do we end up with the correct time, or is an error
introduced because my wife always sets some of the clocks (I never know
which ones) 5 to 10 minutes ahead?

Harold


On Tue, 12 Sep 2000 11:59:22 -0400 Andrew Kunz <TakeThisOuTakunzKILLspamspamspamTDIPOWER.COM>
writes:
{Quote hidden}

FCC Rules Online at http://hallikainen.com/FccRules
Lighting control for theatre and television at http://www.dovesystems.com

________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
dl.http://www.juno.com/get/tagj.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use RemoveMElistservspamspamBeGonemitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@154622 by Dan Michaels

flavicon
face
Peter Schultz wrote:
>Hi Guys,
>I need your opinion in the case of battle with the software QA department.
>They are saying GOTO in C not acceptable.
>I checked the books, some of them said no, some of them saying in some
>places there is a use for GOTO.
>My practice said, when writing code for PIC especially fast operation with
>nested loops
>( like decoding noise RF Manchester transmission at 100 kbit/s ) GOTO is
>absolutely necessary.
>Any thought on that issue?
>


Your s.w. QA guys obviously graduated from one of the "clasical" CS
programs where the profs in CS101 teach Pascal and carry a big heavy
stick that says "Thou shalt not use a GOTO - or I will hit you with
this big heavy stick".

They never tell you, of course, that somewhere deep down inside
the code generated by the Pascal compiler, that there are GOTOs all
over the place. The cpu don't know from do..loop..while..case..etc.
Abstract control structures are just a fancy way of disguising
GOTOs.

In general, you can certainly write all of your C code without ever
using a GOTO - easiest way is to simply use more subroutine calls.

Your QA dept dictates may make more sense when you have a big cpu
with lots of memory and cycles to burn. For a smaller processor,
like the PIC, with limited RAM and execution speed, the "industry
standard" is probably to code closer to the h.w. Maybe you can use
this logic on your guys. [if that fails, code in assembler - and
every 3rd statement will be a GOTO].

[note - this is just an argument I invented for you to try to
flim-flam your QA dept - I personally would *never* use a GOTO
in C - score one for the prof with the big heavy stick].

In a final note, if I ever did use a GOTO in C, it would probably
be only a *local* GOTO used within a subroutine, and not as part
of the overall control structure of the program - which would no
doubt lead to spaghetti code [like I used to write in Basic when
I first learned to program]. In this case, using a GOTO to "speed
up" a bit of code would be acceptable.

best regards,
- Dan Michaels
Oricom Technologies
===================

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use spamBeGonelistserv@spam@spamspam_OUTmitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@155015 by Dan Michaels

flavicon
face
Olin Lathrop wrote:
........
>In short, I think your QA people are being small minded paper pushing weenies.


"trained seals" might have been a little more "diplomatic" here.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use TakeThisOuTlistservspamspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@155403 by Dan Michaels

flavicon
face
Harold M Hallikainen wrote:
>        Though use of a macro or an include file would allow this multiple
>insertion of the code without the insertions diverging. The problem of
>two copies of code and not knowing which is right is like the person with
>two watches never knows what time it is, but the person with one watch
>does. On the watch problem... If we average all the times on all the
>clocks in a time zone, do we end up with the correct time, or is an error
>introduced because my wife always sets some of the clocks (I never know
>which ones) 5 to 10 minutes ahead?
>

That's why they invented the median.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use listservEraseMEspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@162242 by Peter Schultz

flavicon
face
> In a final note, if I ever did use a GOTO in C, it would probably
> be only a *local* GOTO used within a subroutine, and not as part
> of the overall control structure of the program - which would no
> doubt lead to spaghetti code [like I used to write in Basic when
> I first learned to program]. In this case, using a GOTO to "speed
> up" a bit of code would be acceptable.

That is exactly what I was doing, using GOTO only inside a function, to get
out fast from four ongoing while loop without a bunch of flags.
I think HiTech does not even let using GOTO's outside of a function.
Thanks for everybody make me confortable using GOTO's if I have to.
Peter Schultz
Minimed Inc.
12744 San Fernando Road,
Sylmar, CA 91342
Phone: (818) 362-2358x3837
Pager:  (818) 589-3148
E-mail: RemoveMEPeterSEraseMEspamspam_OUTminimed.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use @spam@listservRemoveMEspamEraseMEmitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@163313 by Dan Michaels

flavicon
face
Peter Schulz wrote:
>> In a final note, if I ever did use a GOTO in C, it would probably
>> be only a *local* GOTO used within a subroutine, and not as part
>> of the overall control structure of the program - which would no
>> doubt lead to spaghetti code [like I used to write in Basic when
>> I first learned to program]. In this case, using a GOTO to "speed
>> up" a bit of code would be acceptable.
>
>That is exactly what I was doing, using GOTO only inside a function, to get
>out fast from four ongoing while loop without a bunch of flags.
>I think HiTech does not even let using GOTO's outside of a function.
>Thanks for everybody make me confortable using GOTO's if I have to.


Yeah, but you obviously need some kind of "ruse" [ie, deceit] to
get the QA seals to buy it. That's what I was trying to invent in
the rest of my msg - he, he. [BTW, hopefully your QA seals aren't
monitoring your emails - if so, notify FBI Carnivore immediately].

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use EraseMElistservspam@spam@mitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@163525 by steve

flavicon
face
> > I need your opinion in the case of battle with the software QA department.
> > They are saying GOTO in C not acceptable.

Do they allow "switch" statements which are essentially a computed
goto ?
For that matter, break & continue are too.

When I looked this up I found an interesting comment in Harbison &
Steele that I hadn't really thought about. They comment that the
presence of any label (implicit or explicit) may inhibit compiler
optimizations and therefore slow down a program.

Any comments Clyde, Walter ?

Steve.

======================================================
Steve Baldwin                Electronic Product Design
TLA Microsystems Ltd         Microcontroller Specialists
PO Box 15-680, New Lynn      http://www.tla.co.nz
Auckland, New Zealand        ph  +64 9 820-2221
email: @spam@stevebspam_OUTspam.....tla.co.nz      fax +64 9 820-1929
======================================================

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use spamBeGonelistservEraseMEspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@163729 by Andrew Kunz

flavicon
face
>monitoring your emails - if so, notify FBI Carnivore immediately].

No need - they already know.

Andy

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use listservspamBeGonespammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@164602 by Barry King

flavicon
face
Already a long thread, but a few more points:

1) Is it necessary to make snide side-comments about fatware being
the only thing produced by CS majors?  Can't some of us write really
small, tight code without getting tarred by the fatware brush?
Thanks.

2) You will sometimes see BASIC or assembler programs which "goto" a
place in a different scope.  It is NEVER a good idea (and its illegal
in C) to "goto" out of a function, or into the middle of one, as one
example.  Maintaining the dependancies of variable allocation, etc.
becomes error prone.

3) In places where you might be tempted to "goto", usually "break"
and "continue" will suffice.

Example:

unsigned int GottaGoto()
{
  /* you might THINK you _need_ a goto */
  ReturnCode = DoSomething();
  if (ReturnCode <> AOK) goto Nevermind;
  ReturnCode = SomethingElse();
  if (ReturnCode <> AOK) goto Nevermind;
  /* and so on through many steps*/
Nevermind:
  ExitCleanup;
}

But what I use instead is:

unsigned int NoGotos()
{
  do { /* use a do{} to define the block to the compiler*/
     ReturnCode = DoSomething();
     if (ReturnCode != AOK) break; /* if its broken, break */
     ReturnCode = SomethingElse();
     if (ReturnCode != AOK) break;
     /* and so on through many steps*/
  } while (0); /* do...while encloses the block */

  ExitCleanup();
}

One reason I like this is that I am telling the compiler what I want
done, and let it figure out how to do it.  Clyde's optimiser is
usually smarter than me, and doesn't forget dependancies when
maintaining the code.  Secondly, it is clear that no matter how you
get out the do loop, ExitCleanup() always runs just before returning.

4) That said, even Kernighan and Ritchie admit that when deeply
nested code (in a single function) needs to terminate, a goto may be
the best way to express it.  My example is only preferable when it
works- i.e. only for singly-nested blocks, because "break" only
breaks up one nesting level.

Regards,

Barry.
------------
Barry King, KA1NLH
NRG Systems "Measuring the Wind's Energy"
http://www.nrgsystems.com
Check out the accumulated (PIC) wisdom of the ages at:
PIC/PICList FAQ: http://www.piclist.org

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use RemoveMElistserv@spam@spamspamBeGonemitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@165403 by David VanHorn

flavicon
face
At 04:36 PM 9/12/00 -0400, Andrew Kunz wrote:
> >monitoring your emails - if so, notify FBI Carnivore immediately].

You like Reno's "solution" to the problem? Give it a new name!

--
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use .....listserv@spam@spamEraseMEmitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@170117 by w. v. ooijen / f. hanneman

picon face
> I need your opinion in the case of battle with the software QA
department.
> They are saying GOTO in C not acceptable.
> I checked the books, some of them said no, some of them saying in some
> places there is a use for GOTO.
> My practice said, when writing code for PIC especially fast operation
with
> nested loops
> ( like decoding noise RF Manchester transmission at 100 kbit/s ) GOTO is
> absolutely necessary.

Rules are good but only when a reasonable mechanism exists to decide about
(well motivated) requests to deviate. Most quality standards have such a
mechanism (often called waiver). For a QA department the best motivation
for deviation should be that in some cases (often extreme timing
requirements) the quality can be enhanced (instead of lowered) by using
goto (or inline assembly!). And of course the argument that it is otherwise
impossible should be really convincing, but only if it is really true.

Wouter

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use .....listservRemoveMEspammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@171150 by David VanHorn

flavicon
face
I have a routine for discriminating barcode charachters in assembler.
It does not more than five comparisons on four values, and the result is
direction, parity, and char.

So far, I haven't found any way to code it (efficiently) other than jumps
(asm gotos)

Granted, you COULD write it in C so that a given output was preceeded by a
bunch of conditions, but the result would be hideously large.

As is, it's classic SpaghtttiCode(tm), but it's extremely well documented,
with both theory of operation, and pseudocode included in the comments.

It's small, fast, and has needed ZERO maintainance in over five years.
--
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use .....listservSTOPspamspam@spam@mitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@201029 by Bob Ammerman

picon face
I believe old time mariners had an aphorism:

Sail with one chronograph or three, never two.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Original Message removed}

2000\09\12@201035 by Bob Ammerman

picon face
All ANSI 'C' compilers must allow gotos within a function, even _into_ such
structures as while and for loops and switch statements.

No 'C' compiler should allow gotos from one function to another. I'd love to
here the story of any which does.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

{Original Message removed}

2000\09\12@202103 by David VanHorn

flavicon
face
>
>No 'C' compiler should allow gotos from one function to another. I'd love to
>here the story of any which does.


Beware the coder who knows the answer to this riddle..

--
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use listservEraseMEspam@spam@mitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@210651 by Olin Lathrop

flavicon
face
> >In short, I think your QA people are being small minded paper pushing
weenies.
>
> "trained seals" might have been a little more "diplomatic" here.

Perhaps, but I see little point in being diplomatic with a bunch of small
minded paper pushing weenies ;-)


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, RemoveMEolinspamspamBeGonecognivis.com, http://www.cognivis.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use spamBeGonelistservKILLspamspam@spam@mitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@213051 by Dan Michaels

flavicon
face
Olin Lathrop wrote:
>> >In short, I think your QA people are being small minded paper pushing
>weenies.
>>
>> "trained seals" might have been a little more "diplomatic" here.
>
>Perhaps, but I see little point in being diplomatic with a bunch of small
>minded paper pushing weenies ;-)
>

Neither of us would make a very good politician  :-).

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use listservspam_OUTspam@spam@mitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\12@224054 by Dan Michaels

flavicon
face
Bob Ammerman wrote:

>> > In a final note, if I ever did use a GOTO in C, it would probably
>> > be only a *local* GOTO used within a subroutine, and not as part
>> > of the overall control structure of the program - which would no
>> > doubt lead to spaghetti code [like I used to write in Basic when
>> > I first learned to program]. In this case, using a GOTO to "speed
>> > up" a bit of code would be acceptable.
>>
..............
>All ANSI 'C' compilers must allow gotos within a function, even _into_ such
>structures as while and for loops and switch statements.
>
>No 'C' compiler should allow gotos from one function to another. I'd love to
>here the story of any which does.
>


I guess I didn't make my point very clearly. What I said was I
personally would not use GOTOs "as part of the overall control
structure of the program" [meaning at the highest-most decision-
making levels], but *possibly* would use them in some "low-level"
routines that perform certain specific and limited operations.

For overall program flow control, there are certainly much better
choices - primarily, switch-case. As someone else noted, this is
basically a structured form of a computed-goto that has the
distinct advantage of limiting the number of directions to which
you can jump.

- danM

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use spamBeGonelistserv@spam@spammitvma.mit.edu?body=SET%20PICList%20DIGEST>

2000\09\13@002344 by Olin Lathrop

flavicon
face
> No 'C' compiler should allow gotos from one function to another. I'd love
to
> here the story of any which does.

I don't see how that's possible in C since all functions are separate.

Pascal, however, has the notion of subordinate routines that only exist
within the scope of a single parent routine.  I know of at least one Pascal
compiler that allows GOTOs back to a parent routine.  I was always a bit
weary of it, and wondered if the compiler would properly unwind the stack if
the subordinate routine had called itself recursively, exactly what the
state of returned arguments were, etc.  I wrote a translator from Pascal to
C once, and finally decided to make such GOTOs illegal.  (Imagine trying to
implement such a feature using only standard C without benefit of stack
diddling.)  I kept nested routines because I felt this was a useful
construct although getting all the details right ended up taking quite a bit
of code.  If I remember right, it does multiple passes looking for
references to variables of any of the parent routines.  It keeps doing this
until nothing changes.  Rather a pain to implement but pretty cool once it
all worked.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, RemoveMEolinEraseMEspamKILLspamcognivis.com, http://www.cognivis.com

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspam_OUTspamRemoveMEmitvma.mit.edu>

2000\09\13@025556 by Michael Rigby-Jones

flavicon
face
> -----Original Message-----
> From: Bob Ammerman [SMTP:.....RAMMERMANspamRemoveMEPRODIGY.NET]
> Sent: Tuesday, September 12, 2000 9:31 PM
> To:   PICLISTspam@spam@MITVMA.MIT.EDU
> Subject:      Re: [EE]:GOTO
>
> All ANSI 'C' compilers must allow gotos within a function, even _into_
> such
> structures as while and for loops and switch statements.
>
> No 'C' compiler should allow gotos from one function to another. I'd love
> to
> here the story of any which does.
>
> Bob Ammerman
> RAm Systems
> (contract development of high performance, high function, low-level
> software)
>
Not exactly a "goto" but SETJMP and LONGJMP allow branching between
arbitrary points within different functions.  I've only ever seen this used
on UNIX, so I guess it's not an ANSI C thing?

Mike

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestRemoveMEspamSTOPspammitvma.mit.edu>

2000\09\13@031214 by Bob Ammerman

picon face
> > No 'C' compiler should allow gotos from one function to another. I'd
love
> > to
> > here the story of any which does.
> >

> Not exactly a "goto" but SETJMP and LONGJMP allow branching between
> arbitrary points within different functions.  I've only ever seen this
used
> on UNIX, so I guess it's not an ANSI C thing?
> Mike
>

Ah, an _excellent_ point, and yes, setjmp/longjmp is ANSI.

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestKILLspamspamTakeThisOuTmitvma.mit.edu>

2000\09\13@045349 by o-8859-1?Q?K=FCbek_Tony?=

flavicon
face
Hi,

Barry King wrote:

>2) You will sometimes see BASIC or assembler programs which "goto" a
>place in a different scope.  It is NEVER a good idea (and its illegal
>in C) to "goto" out of a function, or into the middle of one, as one
>example.  Maintaining the dependancies of variable allocation, etc.
>becomes error prone.

Generally - Yes but not 'NEVER', for thoose of You who haven't yet,
i strongly reccomend to look at this:
http://www.microchip.com/10/appnote/listing/index9.htm#a389 ( AN689 ).

This code 'breaks' all these rules, makes all the do not's etc.

There's a time and place for everything.

When programming embedded systems ( in this case PIC's ) then
DO program for these devices and not an 256 Gb ram 1THz Mega computer.

BTW I Agree that this code is 'a bit' hard to follow, but i see
no other possible way to get this much functionality form a 16F84
in any other way.


I rest my case,

/Tony



Tony Kübek, Flintab AB            
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
E-mail: spamBeGonetony.kubekspam@spam@flintab.com
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspam_OUTspammitvma.mit.edu>

2000\09\13@105859 by Walter Banks

picon face
----------
> From: Olin Lathrop <olin_piclistspamspamCOGNIVIS.COM>
>
> Pascal, however, has the notion of subordinate routines that only exist
> within the scope of a single parent routine.


The scoping of variables in C is flexible and logical. Function scoping is
primitive. Nested functions have many advantages including making code
readable.

Walter Banks

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestspam_OUTspamspam_OUTmitvma.mit.edu>

2000\09\13@115926 by Dan Michaels

flavicon
face
Kübek Tony wrote:
{Quote hidden}

This example doesn't really help Peter Schulz's case very much.
First, the code is written in assembler, and not C, and secondly, "most" assembler code that I have seen looks like a spaghetti chef wrote it anyway.
If Peter took this sort of thing to his QA types, they would make him go back and re-take CS101 - Pascal For Non-Programmers.

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspam_OUTspammitvma.mit.edu>

2000\09\13@140643 by Peter L. Peres

picon face
>>No 'C' compiler should allow gotos from one function to another. I'd love
>>to here the story of any which does.
>
>Beware the coder who knows the answer to this riddle..

pick any C compiler that allows inline asm and jump (using a asm
goto/jmp...) between places with equivalently set up stacks (i.e. 2
functions with identical arity, call type, return type, and number of
local variables visible at the location of the jump and of the target
label). Assuming that the jumped into function will not choke on the local
variables in the stack it should work. There was a simple time-sharing
'library' scheme written entirely in C that relied on this but I don't
remember where I saw this.

and why should you beware of me ? ;)

Peter

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu>

2000\09\13@141712 by Bob Ammerman

picon face
----- Original Message -----
From: Peter L. Peres <plpspamBeGonespam.....ACTCOM.CO.IL>
To: <KILLspamPICLISTspam.....MITVMA.MIT.EDU>
Sent: Wednesday, September 13, 2000 3:08 PM
Subject: Re: [EE]:GOTO


> >>No 'C' compiler should allow gotos from one function to another. I'd
love
{Quote hidden}

Yes, this is true, _if_ you can ensure all the mentioned preconditions (not
too difficult) and also determine a target branch to go to. But there are a
couple of issues here:

1: Depending on the way the compiler implements inline assembly language it
may not be possible. Many (most?) compilers use "C" style labels to mark asm
branch targets and these tend to follow normal "C" scoping rules. This
technique just might work in a compiler that compiles to assembly source
code and then assembles it. If is almost certain not to work in a compiler
that compiles directly to object code.

2: One could arguably say that a program that included inline assembly
language was _not_ 'written entirely in C'.

3: Inline assembly is, of course, _not_ ANSI.

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestspamKILLspammitvma.mit.edu>

2000\09\13@150619 by staff

flavicon
face
Bob Ammerman wrote:
{Quote hidden}

Interesting this topic came up. In all my years of coding in
turbo C I only ever use gotos. The turbo c compiler doesn't mind.

I'm actually afraid of using calls and those function() things.
Never trusted that stacker thing that pops and pushes either.
Much safer to use good simple gotos. If <expression> goto HERE
else goto HERE. Works great, nothing can ever go wrong.

Of course you need to write neatly commented code and I especially
like to write down all the gotos I use on a piece of paper, I really
advise beginners to do this as it can get complex without good
records. I still feel this is the best way to write good reliable
C applications. Oh, I almost forgot, I always use global variables,
they are much better as you can use them from anywhere in your
program. I am not sure why people would actually want to limit
themselves to silly functions that can't go anywhere else and silly
variables that the rest of the program can't use. Some people!

Anyway, I better get back to work. Now where did I put that
bit of paper???

Mr. Goto

PS. You should see my Windows apps! "on <mouseclick> goto-" ;o)

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspammitvma.mit.edu>

2000\09\13@152110 by Dan Michaels

flavicon
face
Roman Black wrote:
.........
{Quote hidden}

Hey, Doctor Goto, is it ok if I send your letter to my old Pascal
101 professor? He is collecting this sort of experiences into a book
for publication.

Ok if we include your name and email address too? How about your
phone number? [we want to give credit where credit is due!].

cheers,
- danM

--
http://www.piclist.com hint: To leave the PICList
RemoveMEpiclist-unsubscribe-requestspamBeGonespamRemoveMEmitvma.mit.edu>

2000\09\13@195755 by o-8859-1?Q?K=FCbek_Tony?=

flavicon
face
Hi,

Dan Michaels wrote:

>This example doesn't really help Peter Schulz's case very much.

No, it was meant as an general statement concerning the use of GOTO's
in C or asm ( thread started out as c-only but has since grown ).

>
>First, the code is written in assembler, and not C, and secondly,
>"most" assembler code that I have seen looks like a spaghetti chef
>wrote it anyway.
>

This does not need to be the case, there are no excuses for writing
poorly written/documented code in C, Pascal, asm or whatever.
Ofcource asm, as it is 'lower' level, IS harder to understand/follow
particulary to thoose who do not practice it regulary. And
have you ever amused yourself by looking at the generated output from
an PIC c-compiler :-).
The mentioned example is ( except it's fairly well documented ) as
far as one could take this 'technique' i.e. at one extreme.

Maybe the reason could be that I'm comming from C/C++ and THEN started
with
pic asm affect my personal way of writing programs, structured, well
defined interfaces/functions, alot of comments, etc. I'm not sure
I havent seen any other 'commercial grade' pic software, so I cannot
jugde.


>
>If Peter took this sort of thing to his QA types, they would make
>him go back and re-take CS101 - Pascal For Non-Programmers.
>

May I ask what is CS101 ( sorry I'm not native english so sometimes
need time to catch up :) ) ComputerStudy101 ? ( and yes I know it's some
kind of joke )

/Tony


Tony Kübek, Flintab AB            
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²
E-mail: KILLspamtony.kubekspamBeGonespamflintab.com
²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

--
http://www.piclist.com hint: To leave the PICList
@spam@piclist-unsubscribe-requestSTOPspamspam@spam@mitvma.mit.edu>

2000\09\13@215158 by Dan Michaels

flavicon
face
Kübek Tony wrote:
>Hi,
>
>Dan Michaels wrote:
>
>>This example doesn't really help Peter Schulz's case very much.
>
>No, it was meant as an general statement concerning the use of GOTO's
>in C or asm ( thread started out as c-only but has since grown ).
>

I know, but as you say, the thread has drifted and drifted and drifted.
=================


{Quote hidden}

You are correct - you can write spaghetti/garbage code any number
of ways. Unfortunately, it is much easier to do if you relie on
GOTOs and jumps a lot. The smaller PICs with 2 stack levels beg
for this type of coding - I would never use one of these, myself,
if I could avoid it.
Luckily, the 2nd gen PICs have 8 stack levels, so you can use a lot more subroutine calls, and produce much better structured code.
Personally, I try to make the "overall structure" of my assembler programs look "exactly" like they would look if I were coding in C or other HLL. The difference is mainly in the syntax, not in
the structure. At least this is what I try to do. It is not always the most efficient code, however.
===========


>>If Peter took this sort of thing to his QA types, they would make
>>him go back and re-take CS101 - Pascal For Non-Programmers.
>>
>May I ask what is CS101 ( sorry I'm not native english so sometimes
>need time to catch up :) ) ComputerStudy101 ? ( and yes I know it's some
>kind of joke )
>

Yes, a joke. "Computer Science 101", used in this manner, is generally meant to be taken as the "lowest-level" computer course, given to totally naiive people. Like going back to First Grade or Kindergarten [US terms].
best regards,
- dan michaels

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamBeGonespamspamBeGonemitvma.mit.edu>

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...