linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Glynn Clements <glynn.clements@virgin.net>
To: Charlie Gordon <gmane@chqrlie.org>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: value computed is not used ??
Date: Tue, 1 Jun 2004 22:44:39 +0100	[thread overview]
Message-ID: <16572.63687.904616.93775@cerise.nosuchdomain.co.uk> (raw)
In-Reply-To: <c9iqhv$akj$1@sea.gmane.org>


Charlie Gordon wrote:

> All right, you win.
> It just strikes me as a bad habit to declare main without at least argc and
> argv.
> Proof reading is about idioms, the more you part from proven practices, the
> easier it is to write bug ridden code, and the more tedious it becomes to
> verify said code at code review level.
> For example, for loops written with the <= operator are quite likely to
> contain off by one errors.  It catches my eye instantly, and I tend to be
> rewarded often !  Same remark with casual do/while loops.
> int main(void);  strikes me as 'beginners C code' and trips me off.
> 
> So there is nothing wrong with the prototype,

Ultimately, prototypes exist so that function calls can be
type-checked. As nothing[1] actually calls main(), the prototype is
irrelevant; a K&R-style definition[2] would suffice.

[1] Other than the runtime, which has already been compiled, and so
cannot make use of any prototype.

[2] I.e.:

	int main()
		int argc;
		char **argv;
	{ /* ... */ }

In a K&R-style definition, the argument declarations exist solely so
that the function body can refer to the arguments by name. If the
function doesn't actually use the arguments, there is no point in
declaring them.

> just like there was nothing wrong with rest on the small program :
> it compiles, and performs correctly,

That's a matter of opinion. As you pointed out, initialising an
automatic array is less than ideal; while it will work, it is seldom
the right approach.

But, more generally, the original program clearly wasn't intended to
be a practical utility, but an example. In which case (and coupled
with the fact that it was posted to this list), whether or not it
ultimately "works" is arguably less relevant than whether it was
written "correctly" (in an entirely subjective sense).

> but you will all admit that my other remarks were still making valid
> points.

Yes.

-- 
Glynn Clements <glynn.clements@virgin.net>

  reply	other threads:[~2004-06-01 21:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-01 17:34 value computed is not used ?? Huber, George K RDECOM CERDEC STCD SRI
2004-06-01 19:09 ` Glynn Clements
2004-06-01 20:58   ` Charlie Gordon
2004-06-01 21:44     ` Glynn Clements [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-05-31 19:38 functions to determine dementions of console? Christoph Bussenius
2004-06-01  1:41 ` value computed is not used ?? J.
2004-06-01  3:25   ` Glynn Clements
2004-06-01  7:30   ` Charlie Gordon
2004-06-01 16:08     ` Charlie Gordon
2004-06-01 21:58     ` Glynn Clements
2004-06-03  1:26       ` Micha Feigin

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=16572.63687.904616.93775@cerise.nosuchdomain.co.uk \
    --to=glynn.clements@virgin.net \
    --cc=gmane@chqrlie.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).