FAQ incorrect?

Discussion in 'C Programming' started by nroberts, Aug 4, 2006.

  1. nroberts

    nroberts Guest

    In the faq for this group:

    Q: What's the correct declaration of main()?

    A: There are two valid declarations:

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

    although they can be written in a variety of ways. The second parameter
    may be declared char *argv[] (see question 6.4), you can use any names
    for the two parameters, and you can use old-style syntax:

    int main()

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

    .......... http://c-faq.com/ansi/maindecl.html

    The way this is worded it makes one think that "int main()" is a valid
    declaration of main. However, main is allowed to only take two params
    of (int, char **) or 0, correct? In C is not an empty param list an
    "unspecified" param list? In that case "int main()" would be invalid
    as it matches neither of the standard signatures.

    Another faq claiming to represent this group has the following text for
    the same Q:

    A: Either int main(), int main(void), or int main(int argc,
    char *argv[]) (with alternate spellings of argc and *argv[]
    obviously allowed). See also questions 11.12b to 11.15 below.

    References: ISO Sec. 5.1.2.2.1, Sec. G.5.1; H&S Sec. 20.1 p.
    416; CT&P Sec. 3.10 pp. 50-51.

    ............... http://www.faqs.org/faqs/C-faq/faq/

    It also has "int main()" but has no reasoning for its validity except
    ref to the std I don't have access to. Is that truely a valid
    signature? I always thought you _needed_ (void).
     
    nroberts, Aug 4, 2006
    #1
    1. Advertising

  2. nroberts wrote:
    > ...
    > although they can be written in a variety of ways. The second parameter
    > may be declared char *argv[] (see question 6.4), you can use any names
    > for the two parameters, and you can use old-style syntax:
    >
    > int main()
    >
    > int main(argc, argv)
    > int argc; char **argv;
    >
    > ......... http://c-faq.com/ansi/maindecl.html
    >
    > The way this is worded it makes one think that "int main()" is a valid
    > declaration of main. However, main is allowed to only take two params
    > of (int, char **) or 0, correct? In C is not an empty param list an
    > "unspecified" param list? In that case "int main()" would be invalid
    > as it matches neither of the standard signatures.


    The way it is worded (seeing the "old-style syntax" mentioned and so on) makes
    it clear that it is specifically referring to the declaration of 'main', which
    is a part of _definition_ of 'main'. When the empty parameter list '()' is used
    in a definition, it always means 'no parameters' (equivalent to '(void)'), not
    'unspecified parameters'.

    > ...
    > It also has "int main()" but has no reasoning for its validity except
    > ref to the std I don't have access to. Is that truely a valid
    > signature? I always thought you _needed_ (void).
    > ...


    Only in the declaration that is not a definition. In a definition '()' and
    '(void)' mean the same thing - no parameters.

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Aug 4, 2006
    #2
    1. Advertising

  3. In article <>,
    nroberts <> wrote:
    >In the faq for this group:


    >Q: What's the correct declaration of main()?


    >for the two parameters, and you can use old-style syntax:


    > int main()


    >The way this is worded it makes one think that "int main()" is a valid
    >declaration of main.


    It is.

    > However, main is allowed to only take two params
    >of (int, char **) or 0, correct? In C is not an empty param list an
    >"unspecified" param list?


    According to C89 3.5.4.3, an empty parameter list in a function
    definition indicates that the function takes no parameters. A single
    parameter of void indicates that the function takes no parameters.

    In a function declaration that is not the function definition,
    then the empty parameter list does indicate unspecified arguments.
    --
    Programming is what happens while you're busy making other plans.
     
    Walter Roberson, Aug 4, 2006
    #3
  4. Andrey Tarasevich wrote:
    > ...
    > Only in the declaration that is not a definition. In a definition '()' and
    > '(void)' mean the same thing - no parameters.
    > ...


    Of course, one might argue that the FAQ should state it explicitly that the
    declaration being discussed is actually the _definition_ of 'main'. The standard
    actually uses the term 'definition' when it list the valid forms of 'main'.

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Aug 4, 2006
    #4
  5. nroberts

    jacob navia Guest

    Walter Roberson wrote:
    > In article <>,
    > nroberts <> wrote:
    >
    >>In the faq for this group:

    >
    >
    >>Q: What's the correct declaration of main()?

    >
    >
    >>for the two parameters, and you can use old-style syntax:

    >
    >
    >> int main()

    >
    >
    >>The way this is worded it makes one think that "int main()" is a valid
    >>declaration of main.

    >
    >
    > It is.
    >
    >
    >>However, main is allowed to only take two params
    >>of (int, char **) or 0, correct? In C is not an empty param list an
    >>"unspecified" param list?

    >
    >
    > According to C89 3.5.4.3,


    [snip]

    Irrelevant since that standard is no longer valid.
     
    jacob navia, Aug 4, 2006
    #5
  6. jacob navia said:
    > Walter Roberson wrote:

    <snip>

    >> According to C89 3.5.4.3,

    >
    > [snip]
    >
    > Irrelevant since that standard is no longer valid.


    It's perfectly valid according to a large number of compilers that support
    it and a huge number of programmers who use it. If we were to consider C89
    as invalid, then we would have no valid, widely-implemented C standard,
    which would be a ridiculous state of affairs.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Aug 4, 2006
    #6
  7. In article <>,
    Richard Heathfield <> wrote:
    >jacob navia said:
    >> Walter Roberson wrote:

    ><snip>
    >
    >>> According to C89 3.5.4.3,

    >>
    >> [snip]
    >>
    >> Irrelevant since that standard is no longer valid.

    >
    >It's perfectly valid according to a large number of compilers that support
    >it and a huge number of programmers who use it. If we were to consider C89
    >as invalid, then we would have no valid, widely-implemented C standard,
    >which would be a ridiculous state of affairs.


    But, but, but. Wait a second! Phrases like "large number of
    compilers", "huge number of programmers", "widely implemented" and
    "ridiculous" (this last in the sense of "a condition or position to be
    avoided") have no place in and no traction in CLC. Such references to a
    stupid (not to mention, inconvenient) little thing known as reality
    clearly have no place here. In fact, they are flash-point words that
    uniformly stir the "regs" to action/flaming.

    Really, you need to re-think that post or you may lose your place in the
    he-man newbie-hating society.
     
    Kenny McCormack, Aug 4, 2006
    #7
  8. nroberts

    nroberts Guest

    Kenny McCormack wrote:

    > Really, you need to re-think that post or you may lose your place in the
    > he-man newbie-hating society.


    Hehehe...always interesting how one can inadvertently stir up a bee's
    nest...

    Thanks for the answers, guys.
     
    nroberts, Aug 4, 2006
    #8
  9. On 2006-08-04, nroberts <> wrote:
    >
    > Kenny McCormack wrote:
    >
    >> Really, you need to re-think that post or you may lose your place in the
    >> he-man newbie-hating society.

    >
    > Hehehe...always interesting how one can inadvertently stir up a bee's
    > nest...
    >


    If by `one' you mean yourself, you did nothing wrong. If by `one' you
    mean McCormack, it wasn't inadvertent. He's a troll, and it's best you
    don't respond to his deranged mutterings.

    --
    Andrew Poelstra <http://www.wpsoftware.net/projects>
    To reach me by email, use `apoelstra' at the above domain.
    "Do BOTH ends of the cable need to be plugged in?" -Anon.
     
    Andrew Poelstra, Aug 4, 2006
    #9
  10. jacob navia <> writes:
    > Walter Roberson wrote:
    >> In article <>,
    >> nroberts <> wrote:
    >>
    >>>In the faq for this group:

    >>
    >>>Q: What's the correct declaration of main()?

    >>
    >>>for the two parameters, and you can use old-style syntax:

    >>
    >>> int main()

    >>
    >>>The way this is worded it makes one think that "int main()" is a valid
    >>>declaration of main.

    >> It is.
    >>
    >>>However, main is allowed to only take two params
    >>>of (int, char **) or 0, correct? In C is not an empty param list an
    >>>"unspecified" param list?

    >> According to C89 3.5.4.3,

    >
    > [snip]
    >
    > Irrelevant since that standard is no longer valid.


    So I can safely ignore C89/C90 and program strictly in C99? And I can
    freely use features like, say, designated initializers and structure
    initializers with the dot notation, and not have to worry that some
    compiler might not implement them?

    You wrote two days ago, in comp.compilers.lcc, that lcc-win32 doesn't
    implement those features. Does that mean that lcc-win32 isn't a real
    C compiler?

    You've argued at times that compiler-specific extensions should be
    considered topical here, and at other times that nothing other than
    the C99 standard is topical (as opposed to the generally accepted
    guideline that C99, C95, C89/C90, K&R C, and even earlier versions of
    the language are topical, the latter mostly in historical context).

    If you'll put together a coherent and consistent set of topicality
    guidelines, let us know and we might consider it (no guarantees of
    course) -- or maybe you can set up your own alt.* newsgroup. Until
    then, perhaps you'd consider letting the rest of us work these things
    out for ourselves.

    It is a fact that the C90 standard is still very relevant, and this
    newsgroup is the appropriate place to discuss it, your fantasies to
    the contrary notwithstanding.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Aug 4, 2006
    #10
  11. In article <>,
    Andrew Poelstra <> wrote:
    >On 2006-08-04, nroberts <> wrote:
    >>
    >> Kenny McCormack wrote:
    >>
    >>> Really, you need to re-think that post or you may lose your place in the
    >>> he-man newbie-hating society.

    >>
    >> Hehehe...always interesting how one can inadvertently stir up a bee's
    >> nest...
    >>

    >
    >If by `one' you mean yourself, you did nothing wrong. If by `one' you
    >mean McCormack, it wasn't inadvertent. He's a troll, and it's best you
    >don't respond to his deranged mutterings.


    Pot, kettle, black.
     
    Kenny McCormack, Aug 4, 2006
    #11
  12. nroberts

    jacob navia Guest

    Richard Heathfield wrote:
    > jacob navia said:
    >
    >>Walter Roberson wrote:

    >
    > <snip>
    >
    >>>According to C89 3.5.4.3,

    >>
    >>[snip]
    >>
    >>Irrelevant since that standard is no longer valid.

    >
    >
    > It's perfectly valid according to a large number of compilers that support
    > it and a huge number of programmers who use it. If we were to consider C89
    > as invalid, then we would have no valid, widely-implemented C standard,
    > which would be a ridiculous state of affairs.
    >


    OK OK.

    When I bring a large number of compilers in many OSes
    that support

    #pragma once

    you tell me that it is non-standard.

    When I say that the standard is now

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

    you start with a large number of compilers that support C89.

    There are many compilers that support the K&R standard (without
    prototypes).

    Should we recommned new users that they use that?

    Let's standardize in the standard we use: :)

    The *current* standard.

    The rest is HISTORICAL and just confuses people
     
    jacob navia, Aug 4, 2006
    #12
  13. jacob navia said:

    > Richard Heathfield wrote:
    >> jacob navia said:
    >>
    >>>Walter Roberson wrote:

    >>
    >> <snip>
    >>
    >>>>According to C89 3.5.4.3,
    >>>
    >>>[snip]
    >>>
    >>>Irrelevant since that standard is no longer valid.

    >>
    >>
    >> It's perfectly valid according to a large number of compilers that
    >> support it and a huge number of programmers who use it. If we were to
    >> consider C89 as invalid, then we would have no valid, widely-implemented
    >> C standard, which would be a ridiculous state of affairs.
    >>

    >
    > OK OK.
    >
    > When I bring a large number of compilers in many OSes
    > that support
    >
    > #pragma once
    >
    > you tell me that it is non-standard.


    But your idea of "large number" is a relatively small number, whereas the
    number of compilers conforming to C89 is considerably greater. In fact,
    you'd be hard-pressed to find a C compiler in current use that did not
    conform to C89 (modulo the odd bug), whereas it is so easy to find a C
    compiler that does not support #pragma once that you managed it all by
    yourself.

    > When I say that the standard is now
    >
    > int main(void or int main(int argc,char *argv[])


    you'd be wrong, because the first of your examples is a parenthesis short of
    a declarator.

    > you start with a large number of compilers that support C89.


    Indeed. Note that int main(void) and int main(int argc, char *argv[]) or
    their equivalents have been the forms recommended by clc for many years, so
    I don't see what point you're trying to make here.

    > There are many compilers that support the K&R standard (without
    > prototypes).


    Sure. Whilst they do not conform to C89 (at least, when invoked in K&R
    mode), they nevertheless may prove useful to some people. K&R C is still
    topical here.

    > Should we recommned new users that they use that?


    Only if they are obliged to use K&R compilers.

    > Let's standardize in the standard we use: :)


    It's not up to you and me to determine which flavours of C are topical here.
    By longstanding convention, K&R C, C90, and now C99 are all topical in clc.

    > The *current* standard.


    Fine, as soon as it becomes as widely implemented as C90 currently is, which
    won't be for many years.

    > The rest is HISTORICAL and just confuses people


    The kind of people who make good computer programmers are not the kind of
    people to be confused easily by the fact that a newsgroup might discuss K&R
    C, C90, /and/ C99.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Aug 4, 2006
    #13
  14. Troll alert

    Troll Alert: Kenny McCormack

    The only way to deal with trolls is to limit your reaction to reminding
    others not to respond to trolls.

    --

    Frederick Gotham
     
    Frederick Gotham, Aug 4, 2006
    #14
  15. Troll Alert

    Troll Alert: Kenny McCormack

    The only way to deal with trolls is to limit your reaction to reminding
    others not to respond to trolls.

    --

    Frederick Gotham
     
    Frederick Gotham, Aug 4, 2006
    #15
  16. jacob navia <> writes:
    > Richard Heathfield wrote:
    >> jacob navia said:
    >>
    >>>Walter Roberson wrote:

    >> <snip>
    >>
    >>>>According to C89 3.5.4.3,
    >>>
    >>>[snip]
    >>>
    >>>Irrelevant since that standard is no longer valid.

    >> It's perfectly valid according to a large number of compilers that
    >> support it and a huge number of programmers who use it. If we were
    >> to consider C89 as invalid, then we would have no valid,
    >> widely-implemented C standard, which would be a ridiculous state of
    >> affairs.
    >>

    >
    > OK OK.
    >
    > When I bring a large number of compilers in many OSes
    > that support
    >
    > #pragma once
    >
    > you tell me that it is non-standard.


    Yes, because it is.

    > When I say that the standard is now
    >
    > int main(void or int main(int argc,char *argv[])
    >
    > you start with a large number of compilers that support C89.


    I don't see your point here; that didn't change between C89 and C99
    (except for C99's explicit permission to have more
    implementation-defined forms, but extensions were already permitted).

    > There are many compilers that support the K&R standard (without
    > prototypes).
    >
    > Should we recommned new users that they use that?


    Of course not. There are few C compilers still in common use that
    don't support at least the C89/C90 standard reasonably well. There
    are even fewer platforms still in common use that don't have at least
    *some* compiler that supports at least the C89/C90 standard, even if
    the native compiler doesn't. There is no longer very much point in
    worrying about pre-C89 compilers. On the other hand, if any users run
    into a situation where they need to program in C on a system with no
    modern compiler available, yes, this would be the place to ask for
    advice.

    > Let's standardize in the standard we use: :)
    >
    > The *current* standard.
    >
    > The rest is HISTORICAL and just confuses people


    One more time. The full C89/C90 standard is widely implemented. The
    C99 standard is not. Not everyone uses, or is able to use, the C99
    standard. Even your own lcc-win32 doesn't implement all of it. That
    is reality.

    Will you, just once, *acknowledge* that plain fact? Or will you
    continue to deny reality and make a fool of yourself? (I think I
    already know the answer, but I'm always prepared to be pleasantly
    surprised.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Aug 4, 2006
    #16
  17. Re: Troll Alert

    In article <oSPAg.12272$>,
    Frederick Gotham <> wrote:
    >
    >Troll Alert: Kenny McCormack


    Pot. Kettle. Black.
     
    Kenny McCormack, Aug 5, 2006
    #17
  18. Troll Alert: Kenny McCormack

    The only way to deal with trolls is to limit your reaction to reminding
    others not to respond to trolls.

    --

    Frederick Gotham
     
    Frederick Gotham, Aug 5, 2006
    #18
  19. Re: Troll Alert: Kenny McCormack

    Frederick Gotham <> writes:
    > The only way to deal with trolls is to limit your reaction to reminding
    > others not to respond to trolls.


    Yes, we know.

    Usually someone posts a single followup to anyone who responds to the
    troll in question, and that generally works reasonably well. Starting
    a new thread gives the troll more attention.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Aug 5, 2006
    #19
  20. nroberts

    Jack Klein Guest

    On Fri, 04 Aug 2006 18:38:18 +0200, jacob navia
    <> wrote in comp.lang.c:

    > Walter Roberson wrote:
    > > In article <>,
    > > nroberts <> wrote:
    > >
    > >>In the faq for this group:

    > >
    > >
    > >>Q: What's the correct declaration of main()?

    > >
    > >
    > >>for the two parameters, and you can use old-style syntax:

    > >
    > >
    > >> int main()

    > >
    > >
    > >>The way this is worded it makes one think that "int main()" is a valid
    > >>declaration of main.

    > >
    > >
    > > It is.
    > >
    > >
    > >>However, main is allowed to only take two params
    > >>of (int, char **) or 0, correct? In C is not an empty param list an
    > >>"unspecified" param list?

    > >
    > >
    > > According to C89 3.5.4.3,

    >
    > [snip]
    >
    > Irrelevant since that standard is no longer valid.


    Jacob, you're getting to be a real PITA. Since the text is
    essentially the same in the current standard, it makes no real
    difference.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
     
    Jack Klein, Aug 5, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-15?Q?Stefan_Schw=E4rzler?=

    what's incorrect ALIAS

    =?ISO-8859-15?Q?Stefan_Schw=E4rzler?=, Aug 3, 2005, in forum: VHDL
    Replies:
    1
    Views:
    468
    Jonathan Bromley
    Aug 4, 2005
  2. =?ISO-8859-15?Q?Juli=E1n?= Albo

    FAQ or not FAQ?

    =?ISO-8859-15?Q?Juli=E1n?= Albo, Jan 8, 2007, in forum: C++
    Replies:
    28
    Views:
    889
    Grizlyk
    Jan 15, 2007
  3. Josef 'Jupp' Schugt
    Replies:
    0
    Views:
    224
    Josef 'Jupp' Schugt
    Sep 22, 2003
  4. FAQ server

    FAQ - How do I direct someone to this FAQ?

    FAQ server, Aug 4, 2006, in forum: Javascript
    Replies:
    1
    Views:
    176
    Dr John Stockton
    Aug 4, 2006
  5. Peter Michaux

    FAQ/FAQ notes site makeover

    Peter Michaux, Nov 22, 2006, in forum: Javascript
    Replies:
    22
    Views:
    373
    Randy Webb
    Nov 27, 2006
Loading...

Share This Page