Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ANSI C main()

0 views
Skip to first unread message

Nicolas

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
Which of these are ANSI C-compliant?

void main(void),void main(),main(void),main() or others?

Please answer.Thank you.

--
Posted via CNET Help.com
http://www.help.com/

Michael Farnham

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to

Nicolas <sct_n...@hotmail.com> wrote in message
news:sflmct...@corp.supernews.com...


> Which of these are ANSI C-compliant?
>
> void main(void),void main(),main(void),main() or others?
>
> Please answer.Thank you.
>

Others.

int main()
int main(void) - This is preferred over int main()
int main(int argc, char **argv)

These are the only forms of main
that comply with the new standard (c99)


Regards
Mike Farnham

Regis

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
Michael Farnham wrote:

> int main()
> int main(void) - This is preferred over int main()
> int main(int argc, char **argv)
>
> These are the only forms of main
> that comply with the new standard (c99)

So is
int main(int argc, char **argv, char** envp)
unix-specific ?

Regis

Marco Natoni

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
Hi Michael, how are you?

Michael Farnham wrote:
> int main()
> int main(void) - This is preferred over int main()
> int main(int argc, char **argv)
> These are the only forms of main that comply with the new
> standard (c99)

"Old" standard provided the forms

main()
main(void)
main(int argc,char **argv)

with the return type implied as int. Does the new standard the same, or
this feature is to be considered obsolete? Thank you.


Best regards,
Marco

>
> Regards
> Mike Farnham

Martin Ambuhl

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to

Nicolas wrote:
>
> Which of these are ANSI C-compliant?
>
> void main(void),void main(),main(void),main() or others?

[assuming a hosted implementation]
In the current standard (C99), none of the above is legal.
In the old standard (C89/90)
main()
and
main(void)

--
Martin Ambuhl mam...@earthlink.net

What one knows is, in youth, of little moment; they know enough who
know how to learn. - Henry Adams

A thick skin is a gift from God. - Konrad Adenauer
__________________________________________________________
Fight spam now!
Get your free anti-spam service: http://www.brightmail.com

Michael Farnham

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to

Regis <re...@info.unicaen.fr> wrote in message
news:38FAD54A...@info.unicaen.fr...


> Michael Farnham wrote:
>
> > int main()
> > int main(void) - This is preferred over int main()
> > int main(int argc, char **argv)
> >
> > These are the only forms of main
> > that comply with the new standard (c99)
>

> So is
> int main(int argc, char **argv, char** envp)
> unix-specific ?
>


I do not know if that prototype of main is used on Unix. I
do know that the only prototypes of main allowed by C99 in
a hosted environment are the three in my original post. If
your prototype is used in a hosted environment then the program
that uses it is non-conforming.


--
Regards
Mike Farnham.

Martin Ambuhl

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to

Regis wrote:
>
> Michael Farnham wrote:
>
> > int main()
> > int main(void) - This is preferred over int main()
> > int main(int argc, char **argv)
> >
> > These are the only forms of main
> > that comply with the new standard (c99)
>
> So is
> int main(int argc, char **argv, char** envp)
> unix-specific ?

It is non-standard and even in Unix is deprecated.

Michael Farnham

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to

Marco Natoni <bl...@nospam.com> wrote in message
news:38FAE2D1...@nospam.com...


>
> "Old" standard provided the forms
>
> main()
> main(void)
> main(int argc,char **argv)
>
> with the return type implied as int. Does the new standard the
same, or
> this feature is to be considered obsolete? Thank you.
>
>
> Best regards,
> Marco
>

The new standard does not allow functions to use implicit return
types. Since main is required to return an int, these three prototypes
do not conform to C99.


--
Regards
Mike Farnham

Jeremy M. Jancsary

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
Michael Farnham wrote:
>
> int main()
> int main(void) - This is preferred over int main()
> int main(int argc, char **argv)
>
> These are the only forms of main
> that comply with the new standard (c99)

I think

int main(int argc, char *argv[])

complies as well.

--
Regards,

Jeremy M. Jancsary
janc...@gmx.net

/***************************Quote of the Day************************
* *
* I count him braver who overcomes his desires than him who *
* overcomes his enemies, for the hardest victory is the victory *
* over self. *
* *
* -- Aristotle *
* (Floritegium) *
* *
*******************************************************************/

Joona I Palaste

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
Jeremy M. Jancsary <janc...@gmx.net> scribbled the following:

: Michael Farnham wrote:
:>
:> int main()
:> int main(void) - This is preferred over int main()
:> int main(int argc, char **argv)
:>
:> These are the only forms of main
:> that comply with the new standard (c99)

: I think

: int main(int argc, char *argv[])

: complies as well.

Yes it does. But what about:
int main(int argc, char argv[][])
?

--
/-- Joona Palaste (pal...@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #80 D+ ADA N+++ |
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/

"You will be given the plague."
- Montgomery Burns

Mal Kay

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
Joona I Palaste wrote:
>
....

>
> Yes it does. But what about:
> int main(int argc, char argv[][])

No! Not for any function main or otherwise.
In other functions you could use:
int fred(int argc, char argv[][10])
but this is quite different to
int fred(int argc, char **argv)
or
int fred(int argc, char *argv[])
or even
int fred(int argc, char *argv[10])

Malcolm Kay

Kalem J. Norey

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
you wrote:

>int main(int argc, char argv[][])

^^^^^^^^
It is an illegal form.


Mark McIntyre

unread,
Apr 17, 2000, 3:00:00 AM4/17/00
to
On Mon, 17 Apr 2000 09:11:38 +0000, Regis <re...@info.unicaen.fr>
wrote:

>Michael Farnham wrote:
>
>> int main()
>> int main(void) - This is preferred over int main()
>> int main(int argc, char **argv)
>>
>> These are the only forms of main
>> that comply with the new standard (c99)
>

>So is
>int main(int argc, char **argv, char** envp)
>unix-specific ?

Yes. And its deprecated even there because you can do the same thing
portably via the environ global variable.

Mark McIntyre

C- FAQ: http://www.eskimo.com/~scs/C-faq/top.html

Jack Klein

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
On Mon, 17 Apr 2000 05:06:06 -0500, "Michael Farnham"
<MCFA...@prodigy.net> wrote in comp.lang.c:

>
>
> Nicolas <sct_n...@hotmail.com> wrote in message
> news:sflmct...@corp.supernews.com...

> > Which of these are ANSI C-compliant?
> >
> > void main(void),void main(),main(void),main() or others?
> >

> > Please answer.Thank you.
> >
>
> Others.


>
> int main()
> int main(void) - This is preferred over int main()
> int main(int argc, char **argv)
>
> These are the only forms of main
> that comply with the new standard (c99)
>
>

> Regards
> Mike Farnham

He didn't ask about the International Standard, he asked about the
ANSI standard, although he probably did not know the difference. And
at the moment ANSI has not yet approved C99 for procedural reasons.

So at the moment the ANSI standard (9899:1995) allows:

main()
main(void)
int main()
int main(void)

And the variations with argc and argv or equivalents.

According to my last message with ANSI this is expected to change by
the end of April and ANSI will adopt C99. Then the versions without
int will be illegal.

Jack Klein
--
Home: http://jackklein.home.att.net

Jack Klein

unread,
Apr 18, 2000, 3:00:00 AM4/18/00
to
On Mon, 17 Apr 2000 10:17:46 GMT, Martin Ambuhl
<mam...@earthlink.net> wrote in comp.lang.c:

>
>
> Nicolas wrote:
> >
> > Which of these are ANSI C-compliant?
> >
> > void main(void),void main(),main(void),main() or others?
>

> [assuming a hosted implementation]
> In the current standard (C99), none of the above is legal.
> In the old standard (C89/90)
> main()
> and
> main(void)

<sign>

C99 is the current ISO/IEC standard. It is not the current ANSI
standard, it has not yet been approved.

In ANSI 9899:1995 (current American National Standard),

main()

and

main(int argc, char **argy)

are still legal.

</sign>

But they won't be by next month.

0 new messages