On Thu, Nov 16, 2023 at 11:58:42AM +0100, Thomas Schwinge wrote:
> > -main ()
> > +void
> > +main (int)
> >  {
> >    struct tiny x[3];
> >    x[0].c = 10;
> 
> The nvptx back end doesn't like that one:
> 
>     PASS: gcc.c-torture/execute/931004-13.c   -O0  (test for excess errors)
>     [-PASS:-]{+FAIL:+} gcc.c-torture/execute/931004-13.c   -O0  execution test
>     [...]
> 
>     error   : Prototype doesn't match for 'main' [...]
> 
> I'll add handling for this case in (I suppose)
> 'gcc/config/nvptx/nvptx.cc:write_fn_proto_1' if that indeed is a
> conforming declaration of 'main', but is it really?

C23 says
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 10) ; or in some other implementation-defined manner.

10) Thus, int can be replaced by a typedef name defined as int, or the type of 
argv can be written
as char ** argv, or the return type may be specified by typeof(1), and so on.

And then there is
If the return type of the main function is a type compatible with int, a return 
from the initial call
to the main function is equivalent to calling the exit function with the value 
returned by the main
function as its argument;11) reaching the } that terminates the main function 
returns a value of 0. If
the return type is not compatible with int, the termination status returned to 
the host environment
is unspecified.

So, I guess void main (int) could be ok in some implementations, but I don't
think that is the case of our.  Florian, didn't you mean
int
main (void)
or
int
main ()
instead?

Note, I'm using
int
main ()
{
...
}
in most tests and I hope it should be fine both in the pre-C23 way and in
C23.

        Jakub

Reply via email to