You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Philip Martin <ph...@wandisco.com> on 2014/03/01 11:05:01 UTC

Re: svn commit: r1573106 - /subversion/trunk/build/ac-macros/compiler.m4

Branko Čibej <br...@wandisco.com> writes:

> On 28.02.2014 23:57, philip@apache.org wrote:
>> Author: philip
>> Date: Fri Feb 28 22:57:24 2014
>> New Revision: 1573106
>>
>> +  AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(){return 0;}]])]
>
> This bit of source is not valid C90. It should be: int main(void){ ... }

I don't have a copy of the C90 standard but 'int main()' is used in some
of the examples in both the C99 and C++98 standards.

-- 
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*

Re: svn commit: r1573106 - /subversion/trunk/build/ac-macros/compiler.m4

Posted by Philip Martin <ph...@wandisco.com>.
Branko Čibej <br...@wandisco.com> writes:

> "int main(void)" is not equivalent to "int main()" in C; it is in C++.

These are compatible

  int foo(void);
  int foo(){...}

however main is special so I suppose 'int main(){...}' might be
compatible but not equivalent, or I suppose compatiblity may be
irrelevant and it may simply be not equivalent.  I find it hard to
believe the standard intended that distinction particularly since it
uses 'int main(){...}' in examples.  I think it is intended to be
equivalent.

-- 
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*

Re: svn commit: r1573106 - /subversion/trunk/build/ac-macros/compiler.m4

Posted by Branko Čibej <br...@wandisco.com>.
On 02.03.2014 03:56, Philip Martin wrote:
> Branko Čibej <br...@wandisco.com> writes:
>
>> On 02.03.2014 03:15, Philip Martin wrote:
>>> I have no problem with your change but I don't believe a compiler would
>>> reject 'int main()'.  The standard explicitly allows declarations
>>> "equivalent" to the two declarations you give and I believe 'int main()'
>>> qualifies, particularly since some of the examples in the standard use
>>> 'int main()'.
>> The standard allows the compiler to accept other, implementation-defined
>> signatures, but it does not require it to accept them. That's not the
>> same as allowing equivalent declarations. A compiler is perfectly free
>> to raise an error if it sees main defined in anything except the two
>> forms explicitly mentioned in the standard.
> "implementation-defined" is distinct from "equivalent".
>
> 5.1.2.2.1
>
>   "It shall be defined with ...
>
>    or with ...
>
>    or equivalent; or in some implementation-defined manner."
>
> So an "equivalent" definition to the two is required to be accepted.
> Now we could quibble about what exactly is "equivalent" but anything
> that is has to be accepted.

"int main(void)" is not equivalent to "int main()" in C; it is in C++.


-- 
Branko Čibej | Director of Subversion
WANdisco // Non-Stop Data
e. brane@wandisco.com

Re: svn commit: r1573106 - /subversion/trunk/build/ac-macros/compiler.m4

Posted by Philip Martin <ph...@wandisco.com>.
Branko Čibej <br...@wandisco.com> writes:

> On 02.03.2014 03:15, Philip Martin wrote:
>> I have no problem with your change but I don't believe a compiler would
>> reject 'int main()'.  The standard explicitly allows declarations
>> "equivalent" to the two declarations you give and I believe 'int main()'
>> qualifies, particularly since some of the examples in the standard use
>> 'int main()'.
>
> The standard allows the compiler to accept other, implementation-defined
> signatures, but it does not require it to accept them. That's not the
> same as allowing equivalent declarations. A compiler is perfectly free
> to raise an error if it sees main defined in anything except the two
> forms explicitly mentioned in the standard.

"implementation-defined" is distinct from "equivalent".

5.1.2.2.1

  "It shall be defined with ...

   or with ...

   or equivalent; or in some implementation-defined manner."

So an "equivalent" definition to the two is required to be accepted.
Now we could quibble about what exactly is "equivalent" but anything
that is has to be accepted.

-- 
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*

Re: svn commit: r1573106 - /subversion/trunk/build/ac-macros/compiler.m4

Posted by Branko Čibej <br...@wandisco.com>.
On 02.03.2014 03:15, Philip Martin wrote:
> Branko Čibej <br...@wandisco.com> writes:
>
>> However, the 'main' function is explicitly defined to have exactly two
>> forms:
>>
>>     int main(void); // or int main(); in C++
>>
>> and
>>
>>     int main(int argc, char *argv[]);
>>
>> The distinction is unimportant as far as the purpose of he configure
>> test is concerned; but a pedantic compiler may warn, or even refuse to
>> accept, the form you use in the test.
> I have no problem with your change but I don't believe a compiler would
> reject 'int main()'.  The standard explicitly allows declarations
> "equivalent" to the two declarations you give and I believe 'int main()'
> qualifies, particularly since some of the examples in the standard use
> 'int main()'.

The standard allows the compiler to accept other, implementation-defined
signatures, but it does not require it to accept them. That's not the
same as allowing equivalent declarations. A compiler is perfectly free
to raise an error if it sees main defined in anything except the two
forms explicitly mentioned in the standard.

Granted, it's not very likely that you'll find such a compiler; but
given the purpose of this test, it's better not to confuse the outcome
by using slightly non-standard constructs in it.

-- Brane


-- 
Branko Čibej | Director of Subversion
WANdisco // Non-Stop Data
e. brane@wandisco.com

Re: svn commit: r1573106 - /subversion/trunk/build/ac-macros/compiler.m4

Posted by Philip Martin <ph...@wandisco.com>.
Branko Čibej <br...@wandisco.com> writes:

> However, the 'main' function is explicitly defined to have exactly two
> forms:
>
>     int main(void); // or int main(); in C++
>
> and
>
>     int main(int argc, char *argv[]);
>
> The distinction is unimportant as far as the purpose of he configure
> test is concerned; but a pedantic compiler may warn, or even refuse to
> accept, the form you use in the test.

I have no problem with your change but I don't believe a compiler would
reject 'int main()'.  The standard explicitly allows declarations
"equivalent" to the two declarations you give and I believe 'int main()'
qualifies, particularly since some of the examples in the standard use
'int main()'.

-- 
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*

Re: svn commit: r1573106 - /subversion/trunk/build/ac-macros/compiler.m4

Posted by Branko Čibej <br...@wandisco.com>.
On 01.03.2014 11:05, Philip Martin wrote:
> Branko Čibej <br...@wandisco.com> writes:
>
>> On 28.02.2014 23:57, philip@apache.org wrote:
>>> Author: philip
>>> Date: Fri Feb 28 22:57:24 2014
>>> New Revision: 1573106
>>>
>>> +  AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(){return 0;}]])]
>> This bit of source is not valid C90. It should be: int main(void){ ... }
> I don't have a copy of the C90 standard but 'int main()' is used in some
> of the examples in both the C99 and C++98 standards.

Yes, the semantics changed in C++, where name() means the same as
name(void) in C90. The semantics in C99 are the same as in C90; name()
means that the function is variadic and takes any number of arguments.
However, the 'main' function is explicitly defined to have exactly two
forms:

    int main(void); // or int main(); in C++

and

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

The distinction is unimportant as far as the purpose of he configure
test is concerned; but a pedantic compiler may warn, or even refuse to
accept, the form you use in the test.

(FWIW, in C++, you don't need an explicit return statement in 'main',
either; running past the end of the function implies an implicit 'return
0;')

-- Brane


-- 
Branko Čibej | Director of Subversion
WANdisco // Non-Stop Data
e. brane@wandisco.com