Comprehending the standard,some confusion...

Discussion in 'C Programming' started by amit.codename13@gmail.com, Apr 8, 2009.

  1. Guest

    I am trying to comprehend the standard.

    I want to know what does it mean when the standard says something like
    this...

    "The program can have A or B or C"

    does it mean that the implementation has to support "A or B or C" OR
    "A and B and C"
     
    , Apr 8, 2009
    #1
    1. Advertising

  2. Guest

    <> wrote:
    > I am trying to comprehend the standard.
    >
    > I want to know what does it mean when the standard says something like
    > this...
    >
    > "The program can have A or B or C"
    >
    > does it mean that the implementation has to support "A or B or C" OR
    > "A and B and C"


    It's impossible to say. The standard is very carefully worded to mean
    exactly what it says. Your paraphrase above is not. Give us an actual
    quote and we'll be glad to explain it. But note that comp.std.c is a
    better forum for questions about the standard itself than comp.lang.c.
    --
    Larry Jones

    My dreams are getting way too literal. -- Calvin
     
    , Apr 8, 2009
    #2
    1. Advertising

  3. Guest

    On Apr 8, 9:28 pm, Keith Thompson <> wrote:
    > "" <> writes:
    > > I am trying to comprehend the standard.

    >
    > > I want to know what does it mean when the standard says something like
    > > this...

    >
    > > "The program can have A or B or C"

    >
    > > does it mean that the implementation has to support "A or B or C" OR
    > > "A and B and C"

    >
    > It's hard to tell without a specific example. We don't know what you
    > mean by "something like this". If you'll post an actual quote from
    > the standard, including the section number, and we can help you
    > interpret it.
    >
    > --
    > Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    > Nokia
    > "We must do something. This is something. Therefore, we must do this."
    > -- Antony Jay and Jonathan Lynn, "Yes Minister"


    I am quoting the following text from the standard(section 5.1.2.2.1).
    I have removed the examples for clarity...

    >It shall be defined with a return type of int and with no parameters or with two parameters (referred to here as >argc and argv, though any names may be used, as they are local to the function in which they are declared) or in >some other implementation-defined manner.


    I was interpreting the "It shall defined...." as the "program can have
    forms A(int main(void){}) or B(int main(int argc, char *argv[]) {}) or
    C(some other implementation-defined manner)"...

    I want to know if the clause implies "int main(void){} or int main(int
    argc, char *argv[]) {} or some other implementation-defined manner"
    must be supported by the implementation or "int main(void){} and int
    main(int argc, char *argv[]) {} and some other implementation-defined
    manner" must be supported by the implementation?

    thanks
     
    , Apr 8, 2009
    #3
  4. "" <> writes:
    > On Apr 8, 9:28 pm, Keith Thompson <> wrote:
    >> "" <> writes:
    >> > I am trying to comprehend the standard.

    >>
    >> > I want to know what does it mean when the standard says something like
    >> > this...

    >>
    >> > "The program can have A or B or C"

    >>
    >> > does it mean that the implementation has to support "A or B or C" OR
    >> > "A and B and C"

    >>
    >> It's hard to tell without a specific example. We don't know what you
    >> mean by "something like this". If you'll post an actual quote from
    >> the standard, including the section number, and we can help you
    >> interpret it.

    >
    > I am quoting the following text from the standard(section 5.1.2.2.1).
    > I have removed the examples for clarity...
    >
    >>It shall be defined with a return type of int and with no parameters
    >>or with two parameters (referred to here as argc and argv, though
    >>any names may be used, as they are local to the function in which
    >>they are declared) or in some other implementation-defined manner.

    >
    > I was interpreting the "It shall defined...." as the "program can have
    > forms A(int main(void){}) or B(int main(int argc, char *argv[]) {}) or
    > C(some other implementation-defined manner)"...
    >
    > I want to know if the clause implies "int main(void){} or int main(int
    > argc, char *argv[]) {} or some other implementation-defined manner"
    > must be supported by the implementation or "int main(void){} and int
    > main(int argc, char *argv[]) {} and some other implementation-defined
    > manner" must be supported by the implementation?


    I'm still having trouble parsing your question, but I think I can
    answer it anyway.

    An implementation must support "int main(void){}".

    An implementation must also support "int main(int argc, char
    *argv[]){}".

    An implementation must also support definitions that are equivalent to
    either of those, such as:

    signed int main(void);

    typedef int i;
    typedef void v;
    typedef char c;
    #define m main
    i m(i a, c **v);

    An implementation *may*, but need not, support additional
    implementation-defined forms, such as:

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

    So if you have one program that defines "int main(void){}" and another
    than defines "int main(int argc, char *argv[]){}", then the
    implementation must support each of them. Which form to use is the
    choice of the programmer, not of the implementation. (Using both in
    the same program is invalid.)

    Does that answer your question?

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Apr 8, 2009
    #4
  5. On 8 Apr, 18:38, ""
    <> wrote:
    >
    > I am quoting the following text from the standard(section 5.1.2.2.1).
    > I have removed the examples for clarity...
    >
    > >It shall be defined with a return type of int and with no parameters or with two parameters (referred to here as >argc and argv, though any names may be used, as they are local to the function in which they are declared) or in >some other implementation-defined manner.

    >
    > I was interpreting the "It shall defined...." as the "program can have
    > forms A(int main(void){}) or B(int main(int argc, char *argv[]) {}) or
    > C(some other implementation-defined manner)"...
    >
    > I want to know if the clause implies "int main(void){} or int main(int
    > argc, char *argv[]) {} or some other implementation-defined manner"
    > must be supported by the implementation or "int main(void){} and int
    > main(int argc, char *argv[]) {} and some other implementation-defined
    > manner" must be supported by the implementation?


    Although Keith Thompson has already answered your question you
    might also find useful the following post and those close to it:
    http://tinyurl.com/csr3dm
    Long link is
    <
    http://groups.google.co.uk/group/co.../656b70a36686e90f?tvc=1&#doc_7a2b2d610f18c470
    >
     
    Spiros Bousbouras, Apr 8, 2009
    #5
  6. CBFalconer Guest

    "" wrote:
    >
    > On Apr 8, 9:28 pm, Keith Thompson <> wrote:
    > > "" <> writes:
    > > > I am trying to comprehend the standard.

    > >
    > > > I want to know what does it mean when the standard says something like
    > > > this...

    > >
    > > > "The program can have A or B or C"

    > >
    > > > does it mean that the implementation has to support "A or B or C" OR
    > > > "A and B and C"

    > >
    > > It's hard to tell without a specific example. We don't know what you
    > > mean by "something like this". If you'll post an actual quote from
    > > the standard, including the section number, and we can help you
    > > interpret it.
    > >
    > > --
    > > Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    > > Nokia
    > > "We must do something. This is something. Therefore, we must do this."
    > > -- Antony Jay and Jonathan Lynn, "Yes Minister"

    >
    > I am quoting the following text from the standard(section 5.1.2.2.1).
    > I have removed the examples for clarity...
    >
    > >It shall be defined with a return type of int and with no parameters or with two parameters (referred to here as >argc and argv, though any names may be used, as they are local to the function in which they are declared) or in >some other implementation-defined manner.

    >
    > I was interpreting the "It shall defined...." as the "program can have
    > forms A(int main(void){}) or B(int main(int argc, char *argv[]) {}) or
    > C(some other implementation-defined manner)"...
    >
    > I want to know if the clause implies "int main(void){} or int main(int
    > argc, char *argv[]) {} or some other implementation-defined manner"
    > must be supported by the implementation or "int main(void){} and int
    > main(int argc, char *argv[]) {} and some other implementation-defined
    > manner" must be supported by the implementation?


    I think you meant to quote the following:

    5.1.2.2.1 Program startup

    [#1] 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 here 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;8) or in some other implementation-defined
    manner.

    which says that the two listed versions are correct. An
    implementation may also allow some other startup call, which cannot
    be portable, and thus should be avoided.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.
     
    CBFalconer, Apr 9, 2009
    #6
  7. CBFalconer <> writes:
    > "" wrote:

    [...]
    >> I am quoting the following text from the standard(section 5.1.2.2.1).
    >> I have removed the examples for clarity...
    >>

    [snip]
    >> I was interpreting the "It shall defined...." as the "program can have
    >> forms A(int main(void){}) or B(int main(int argc, char *argv[]) {}) or
    >> C(some other implementation-defined manner)"...
    >>
    >> I want to know if the clause implies "int main(void){} or int main(int
    >> argc, char *argv[]) {} or some other implementation-defined manner"
    >> must be supported by the implementation or "int main(void){} and int
    >> main(int argc, char *argv[]) {} and some other implementation-defined
    >> manner" must be supported by the implementation?

    >
    > I think you meant to quote the following:
    >
    > 5.1.2.2.1 Program startup

    [snip]

    > [#1] 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 here 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;8) or in some other implementation-defined
    > manner.
    >
    > which says that the two listed versions are correct. An
    > implementation may also allow some other startup call, which cannot
    > be portable, and thus should be avoided.


    Yes, I'm sure he did mean to quote that section. And, in fact, he
    did, omitting portions that were irrelevant to his question. So why
    did you repeat it?

    I think he came up with a rather unusual interpretation of that
    section, one that I think is actually consistent with the wording.
    Specifically, the interpretation is that an implementation must permit

    int main(void) { /* ... */ }

    *or* it must permit

    int main(int argc, char *argv[]) { /* ... */ }

    *or* some other implementation-defined definition. So one
    implementation might support the zero-argument form (and reject
    anything else), and another implementation might support the
    two-argument form (and reject anything else), and so on. So the
    question is whether the "or" implies a choice for the implementation
    (to which the programmer must conform), or a choice for the programmer
    (which the implementation must support either way).

    Now I'm sure beyond reasonable doubt that that wasn't the intent, and
    the "correct" interpretation (that an implementation must support both
    forms, and a program can use either) is also consistent with the
    wording. But the alternative interpretation isn't entirely
    nonsensical; after all, the idea that the environment can call a
    function that might have either of two declarations is itself rather
    odd, and the allowance for implementation-defined definitions already
    means that a program that's valid for one implementation might be
    rejected by another.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Apr 9, 2009
    #7
  8. Old Wolf Guest

    On Apr 9, 2:02 pm, Keith Thompson <> wrote:
    |> I think he came up with a rather unusual interpretation of that
    > section, one that I think is actually consistent with the wording.
    > Specifically, the interpretation is that an implementation must permit
    >
    >     int main(void) { /* ... */ }
    >
    > *or* it must permit
    >
    >     int main(int argc, char *argv[]) { /* ... */ }
    >
    > *or* some other implementation-defined definition.  So one
    > implementation might support the zero-argument form (and reject
    > anything else), and another implementation might support the
    > two-argument form (and reject anything else), and so on.  


    The text says that a program may define main
    in form A or form B or form C. Consequentially,
    the implementation must support all of those forms.

    (Perhaps you misread it as saying something like
    "the implementation must support form A or form B
    or form C", which would indeed be an ambiguous statement).
     
    Old Wolf, Apr 9, 2009
    #8
  9. Old Wolf <> writes:
    > On Apr 9, 2:02 pm, Keith Thompson <> wrote:
    > |> I think he came up with a rather unusual interpretation of that
    >> section, one that I think is actually consistent with the wording.
    >> Specifically, the interpretation is that an implementation must permit
    >>
    >>     int main(void) { /* ... */ }
    >>
    >> *or* it must permit
    >>
    >>     int main(int argc, char *argv[]) { /* ... */ }
    >>
    >> *or* some other implementation-defined definition.  So one
    >> implementation might support the zero-argument form (and reject
    >> anything else), and another implementation might support the
    >> two-argument form (and reject anything else), and so on.  

    >
    > The text says that a program may define main
    > in form A or form B or form C. Consequentially,
    > the implementation must support all of those forms.


    The exact wording is important. It doesn't say a program *may* define
    main in those ways. It says:

    It [main] shall be defined with a return type of int and with no
    parameters [...] or with two parameters [...] or equivalent; or in
    some other implementation-defined manner.

    I don't think it's too much of a stretch to read that and think that
    the choice is up to the implementation.

    > (Perhaps you misread it as saying something like
    > "the implementation must support form A or form B
    > or form C", which would indeed be an ambiguous statement).


    No, but in any case, we all know the actual intent.

    If we had a formal specification, it would be clear whether it's
    ambiguous or not. (And I just realized that last sentence is
    ambiguous.) But it would be clear only to people who can read formal
    specifications.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Apr 9, 2009
    #9
  10. Guest

    Keith Thompson <> wrote:
    >
    > The exact wording is important. It doesn't say a program *may* define
    > main in those ways. It says:
    >
    > It [main] shall be defined with a return type of int and with no
    > parameters [...] or with two parameters [...] or equivalent; or in
    > some other implementation-defined manner.
    >
    > I don't think it's too much of a stretch to read that and think that
    > the choice is up to the implementation.


    I do. Implementations don't define functions other than library
    functions, translation units do. Therefore, the requirement is clearly
    on translations units. Since a correct translation unit is permitted to
    use any of those forms, a conforming implementation must accept all of
    them.
    --
    Larry Jones

    I'll be a hulking, surly teen-ager before you know it!! -- Calvin
     
    , Apr 9, 2009
    #10
    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. Mark Healey
    Replies:
    4
    Views:
    318
    Ben C
    Apr 16, 2006
  2. Y2J
    Replies:
    5
    Views:
    348
    Victor Bazarov
    Aug 19, 2006
  3. Replies:
    0
    Views:
    335
  4. Nick Black
    Replies:
    1
    Views:
    191
    Kashia Buch
    Nov 16, 2006
  5. Old Echo
    Replies:
    8
    Views:
    124
    Robert Klemme
    Jun 14, 2008
Loading...

Share This Page