Mail Archives: djgpp/2000/08/03/19:27:57
---==--=---==----===-==-=--=-====----=--===-==--==
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"; format=flowed
I was just pointing out that getting into the habit of using goto makes it
far too easy to short-circuit things that the programmer *was* clueful
enough to do. Lets say that you malloc() at the beginng of a *huge* nested
loop and free() at the end. However, you find that you need to break out
early and forget about the malloc(). Using goto would introduce a leak that
may be hard to find. I'm not saying don't goto, just to apply good
technique to using it. Make sure you step through the loop to make sure you
don't need anything in it after that level, etc. It shouldn't be used as a
cure-all. Which many people see it as at first. (Until something goes
"Boom!" and they never touch it again...)
And I'm a proponent of using perl/python/etc. for CGIs. Especially if you
can't thoroughly test it from a command line first...
I just try to be paranoid. ;)
--Matt
At 03:41 PM 8/3/00, J-P wrote:
>In article <4 DOT 3 DOT 2 DOT 7 DOT 0 DOT 20000803145250 DOT 00aa2310 AT mail DOT subdimension DOT com>,
>Matt Lewandowsky <djgpp AT delorie DOT com> wrote:
> >One good reason to keep in mind: you may get into the habit of using it.
> >And in C, it's a worse habit than BASIC. Let's say that you have an
> >oft-used loop whose nesting make this one look simple. Let's say you want
> >to break out of it simply. Lets say that you forgot there's a free() five
> >levels out after this point. You use goto. See a potential problem?
>
>If you're going to worry about that sort of thing, you should maybe quit
>using C and go for, say, Perl or something. C assumes in so /many/ places
>that you're clueful enough to free() what you malloc(), or check your
>malloc()s to make sure they don't point to NULL. C is, all things being
>equal, not safe. goto is a tool like anything else in C and whilst it
>should only be used with care, so should sprintf().
>
>(The comparison with Perl is only there because someone crashed our server
>with a fscked C++ CGI script a week ago... I think he did something
>insane with malloc()s, which he shouldn't have been using in C++
>anyways.... :-/ )
>
>J-P
---==--=---==----===-==-=--=-====----=--===-==--==
Content-Type: application/pgp-signature
-----BEGIN PGP MESSAGE-----
Version: PGPfreeware 6.5.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBOYn/ZuoMko8dOmunEQIHdQCg+wAZcI46tIue3wog12Jr8Y48hGkAoJYc
rz4fmOPinzTpsdKPcbpgpvLq
=2XOo
-----END PGP MESSAGE-----
---==--=---==----===-==-=--=-====----=--===-==--==--
- Raw text -