Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #67347

Re: Can main() be called by itself?

From Melzzzzz <mel@zzzzz.com>
Newsgroups comp.lang.c
Subject Re: Can main() be called by itself?
Date 2015-08-14 01:58 +0200
Organization albasani.net
Message-ID <20150814015809.636b77cf@maxa-pc> (permalink)
References <39b9ef39-3874-4983-8165-035b51b78827@googlegroups.com>

Show all headers | View raw


On Thu, 13 Aug 2015 16:51:28 -0700 (PDT)
fl <rxjwg98@gmail.com> wrote:

> Hi,
> 
> Recently, I had a quiz onsite. It looks like below, but it is not
> exactly (I cannot remember its exact form now).
> 
> 
> 
> int main(int a)
> {
> int temp;
> 
> 	temp = main(3);
> 
> 	return temp;
> 
> }
> 
> 
> In the exam, I thought main() can call itself, and gave a value to
> the answer.
> 
> Now, the above main() can build, but it has stack overflow when
> running at MSVC. So, could you experts think main() can call itself?
> And if it is Yes, can you give me a correct form to replace the above
> code?
> 
> 
> Thanks a lot.

You have infinite recursion and wrong prototype.
Problem is that I don't know if main itself is allowed to set up
argc/argv parameters. If this is so main cannot be called like
ordinary function.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Can main() be called by itself? fl <rxjwg98@gmail.com> - 2015-08-13 16:51 -0700
  Re: Can main() be called by itself? Melzzzzz <mel@zzzzz.com> - 2015-08-14 01:58 +0200
  Re: Can main() be called by itself? James Kuyper <jameskuyper@verizon.net> - 2015-08-13 23:32 -0400
    Re: Can main() be called by itself? Keith Thompson <kst-u@mib.org> - 2015-08-14 11:14 -0700
  Re: Can main() be called by itself? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-08-13 22:14 -0600
    Re: Can main() be called by itself? Keith Thompson <kst-u@mib.org> - 2015-08-14 11:15 -0700
  Re: Can main() be called by itself? gordonb.mj8yu@burditt.org (Gordon Burditt) - 2015-08-14 01:52 -0500
    Re: Can main() be called by itself? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-14 11:46 +0100
      Re: Can main() be called by itself? James Kuyper <jameskuyper@verizon.net> - 2015-08-14 07:54 -0400
        Re: Can main() be called by itself? Melzzzzz <mel@zzzzz.com> - 2015-08-14 14:19 +0200
          Re: Can main() be called by itself? David Brown <david.brown@hesbynett.no> - 2015-08-14 14:50 +0200
            Re: Can main() be called by itself? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-16 10:39 -0700
      Re: Can main() be called by itself? gazelle@shell.xmission.com (Kenny McCormack) - 2015-08-14 12:32 +0000

csiph-web