Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > main() called inside main()

Reply
Thread Tools

main() called inside main()

 
 
Ian Collins
Guest
Posts: n/a
 
      05-04-2006
Jordan Abel wrote:
> On 2006-05-04, Ian Collins <(E-Mail Removed)> wrote:
>
>>Jordan Abel wrote:
>>
>>>On 2006-05-04, Keith Thompson <(E-Mail Removed)> wrote:
>>>>
>>>>I'm fairly sure it is, since the standard doesn't define what the
>>>>behavior is.
>>>
>>>
>>>I guess i'm used to thinking of UB as something that can at least in
>>>principle be identified by careful examination of the source. that is,
>>>for any given set of inputs ["inputs" including returns from library
>>>functions whose outputs are not fully determined by their inputs - e.g.
>>>malloc returning null or not], a program either does cause UB or
>>>doesn't. stack overflows are a big hole in this, and i think they're
>>>unique.

>>
>>Are they UB and are they unique?
>>
>>I'd categorise them as an environment constraint violation, another
>>example would be opening more files then the operating environment permits.

>
>
> That doesn't cause UB. It causes fopen to return a null pointer.
>

OK.
>
>>Stack size is environment specific, so a well formed program that
>>operates correctly in one environment might violate the constraints of
>>another.

>
>
> Which is unique among ALL things which cause UB.
>

How about dereferencing an odd address on a target the doesn't support this?

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Jordan Abel
Guest
Posts: n/a
 
      05-04-2006
On 2006-05-04, Ian Collins <(E-Mail Removed)> wrote:
> Jordan Abel wrote:
>> On 2006-05-04, Ian Collins <(E-Mail Removed)> wrote:
>>
>>>Jordan Abel wrote:
>>>
>>>>On 2006-05-04, Keith Thompson <(E-Mail Removed)> wrote:
>>>>>
>>>>>I'm fairly sure it is, since the standard doesn't define what the
>>>>>behavior is.
>>>>
>>>>
>>>>I guess i'm used to thinking of UB as something that can at least in
>>>>principle be identified by careful examination of the source. that is,
>>>>for any given set of inputs ["inputs" including returns from library
>>>>functions whose outputs are not fully determined by their inputs - e.g.
>>>>malloc returning null or not], a program either does cause UB or
>>>>doesn't. stack overflows are a big hole in this, and i think they're
>>>>unique.
>>>
>>>Are they UB and are they unique?
>>>
>>>I'd categorise them as an environment constraint violation, another
>>>example would be opening more files then the operating environment permits.

>>
>>
>> That doesn't cause UB. It causes fopen to return a null pointer.
>>

> OK.
>>
>>>Stack size is environment specific, so a well formed program that
>>>operates correctly in one environment might violate the constraints of
>>>another.

>>
>>
>> Which is unique among ALL things which cause UB.
>>

> How about dereferencing an odd address on a target the doesn't support
> this?


Things that would cause this to happen ALWAYS cause UB. UB doesn't
always mean something bad happens.
 
Reply With Quote
 
 
 
 
Robert Smith
Guest
Posts: n/a
 
      05-05-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> hi,
>
> int main(void)
> {
> main();
> return 0;
> }
>
> wat does the standard says about the above code snippet?
>


This is allowed in C and performs the obvious useless recursive call. It is
forbidden however in the C++ standard


 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      05-05-2006
Robert Smith wrote:
> <(E-Mail Removed)> wrote in message
>>
>> int main(void)
>> {
>> main();
>> return 0;
>> }
>>
>> wat does the standard says about the above code snippet?

>
> This is allowed in C and performs the obvious useless recursive
> call. It is forbidden however in the C++ standard


In C it is of primary use in writing obfuscated code. C++ needs no
assistance in this respect, and thus can dispense with the
capability.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>


 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      05-07-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) said:

> hi,
>
> int main(void)
> {
> main();
> return 0;
> }
>
> wat does the standard says about the above code snippet?


Not a lot.

It's legal C, but eventually you'll run out of something or other, depending
on what system you are using.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie -- smart pointer destructor called without destructor everbeing called Jimmy Hartzell C++ 2 05-20-2008 02:20 AM
newbie -- smart pointer destructor called without destructor everbeing called Jimmy Hartzell C++ 0 05-19-2008 07:05 PM
Why is a button Click event also called when a textbox TextChanged event is called??? S_K ASP .Net 6 11-08-2007 07:44 PM
What is called carry chain structure in FPGA is called in IC? Weng Tianxiang VHDL 6 09-12-2007 07:19 AM
three times copy ctor called, one ctor called, why? Apricot C++ 4 04-16-2004 07:55 AM



Advertisments