linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Charlie Gordon" <gmane@chqrlie.org>
To: linux-c-programming@vger.kernel.org
Subject: Re: value computed is not used ??
Date: Tue, 1 Jun 2004 22:58:27 +0200	[thread overview]
Message-ID: <c9iqhv$akj$1@sea.gmane.org> (raw)
In-Reply-To: 16572.54376.258083.671154@cerise.nosuchdomain.co.uk

> > I to am a little confused on why you state that int main(void) is an
> > incorrect
> > prototype for main?  Quoting from the C99 - draft standard,
> >
> > "The function called at program startup is named main.  The
implementation
> > declares
> > no prototype for this function.  It shall be defined with a return type
of
> > int and with
> > no parameters:
> >     int main(void) {/* ... */}
> > or with two parameters (referred to hear as argc and argv, though any
names
> > may be used,
> > as they are local to the function in which they are declared):
> >     int main(int argc, char* argv[]) {/* ... *.}
> > or equivalent, or in some other implementation-defined manner." (section
> > 5.1.2.2.1)
> >
>
> If a function uses the C calling convention (which is true for almost
> everything except for functions which are exported from Windows DLLs),
> you can safely supply more arguments than the function expects. So
> long as the run-time supplies argc and argv, either prototype will
> actually work.
>
> In practice, Unix systems tend to use:
>
> int main(int argc, char **argv, char **envp)
>
> where envp is the array of environment variables (also available
> through the global variable "environ").
>
> So you can declare main() with any subset of these arguments, i.e. any
> of:
>
> int main(void)
> int main(int argc)
> int main(int argc, char **argv)
> int main(int argc, char **argv, char **envp)
>

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, just like there was nothing
wrong with rest on the small program : it compiles, and performs correctly,
but you will all admit that my other remarks were still making valid points.

Chqrlie.






  reply	other threads:[~2004-06-01 20:58 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 [this message]
2004-06-01 21:44     ` Glynn Clements
  -- 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='c9iqhv$akj$1@sea.gmane.org' \
    --to=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).