From: James Colannino <james@colannino.org>
To: linux-c-programming@vger.kernel.org
Subject: Re: Code critique: checking for syntax errors
Date: Mon, 23 Jan 2006 11:47:34 -0800 [thread overview]
Message-ID: <43D532D6.9050204@colannino.org> (raw)
In-Reply-To: <43D35194.4050206@ajp-services.net>
Jesse Ruffin wrote:
> If you can at all manage it, and most times you can, put all of your
> variable declarations right at the beginning of the function. This also
> implies moving your debug statements below them as they will be compiled
> in sometime. Doing so will aid in portability to older, or more strict,
> compilers.
Do stricter and older compilers complain if variables aren't declared at
the beginning of the function?
> And try extra hard to avoid variable declarations in the loop
> definition, as this is often seen as an error by compilers unless you
> are using the C99 standard.
Actually, I was banking on the C99 standard (I guess perhaps it would
have been wise for me to say so when I posted the code.)
>
> Multiple locations:
> | if (ungetc(character, input) == NULL) {
>
> ungetc() returns an EOF on error[...]
You're right. I changed that :)
> C defines two values, EXIT_SUCCESS and EXIT_FAILURE, that should be used
> for the exit() value. These will pass the proper value to the host
> environment. As that value may differ, you should use them to make your
> code as portable as possible.
I can understand EXIT_FAILURE, but why do all the C books tell you to
return 0 instead of EXIT_SUCCESS? I always thought that both return()
and exit() did the same basic thing, so I'm confused as to why a book
teaching how to write portable code would say to simply use 0 (that's
with return() and not exit().) I have implemented exit(EXIT_FAILURE)
instead of exit(1).
>
> Once again, I think that this is good code overall. It's good to see
> people being careful and using extra parenthesis and braces, rather than
> hunting down logic bugs caused by a lack of them.
Thanks. I do try hard to be explicit and to comment when necessary. I
still have a lot of work to do, but hopefully I'm getting there.
James
--
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/
"If Carpenters made houses the way programmers design programs, the first woodpecker to come along would destroy all of civilization." --Computer Proverb
next prev parent reply other threads:[~2006-01-23 19:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-21 19:10 Code critique: checking for syntax errors James Colannino
2006-01-22 9:34 ` Jesse Ruffin
2006-01-23 19:47 ` James Colannino [this message]
2006-01-23 22:37 ` Jesse Ruffin
2006-01-23 22:59 ` James Colannino
2006-01-24 0:44 ` Jesse Ruffin
2006-01-24 2:06 ` James Colannino
2006-01-24 9:34 ` Glynn Clements
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43D532D6.9050204@colannino.org \
--to=james@colannino.org \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.