Comprehending the standard,some confusion...

  • Thread starter amit.codename13
  • Start date
A

amit.codename13

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"
 
L

lawrence.jones

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.
 
A

amit.codename13

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) (e-mail address removed) <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
 
K

Keith Thompson

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?
 
S

Spiros Bousbouras

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
 
C

CBFalconer

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) (e-mail address removed) <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.
 
K

Keith Thompson

CBFalconer said:
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.
 
O

Old Wolf

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).
 
K

Keith Thompson

Old Wolf said:
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.
 
L

lawrence.jones

Keith Thompson said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top