Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3392492
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:55:39+00:00 2026-05-18T03:55:39+00:00

I could have also phrased this as What constitutes observable behavior? The C++ Standard

  • 0

I could have also phrased this as What constitutes observable behavior?

The C++ Standard talks a lot about observable behavior, but I am not really sure if program termination is part of observable behavior.

That is, given a program such as:

int main() {
  for(;;) {}
  return 0;
}

is a conforming implementation allowed to ever terminate this program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:55:40+00:00Added an answer on May 18, 2026 at 3:55 am

    Yes it is legal for the compile to generate an empty main body for the above code (thus terminating almost immediately).

    The C++0x FCD says 6.5 says (pay special attention to the note):

    A loop that, outside of the for-init-statement in the case of a for statement,
    * makes no calls to library I/O functions, and
    * does not access or modify volatile objects, and
    * performs no synchronization operations (1.10) or atomic operations (Clause 29)

    may be assumed by the implementation to terminate. [ Note: This is intended to allow compiler transformations, such as removal of empty loops, even when termination cannot be proven. — end note ]

    So the compiler can assume that your for loop will terminate and since the body is empty it can optimize it away altogether.


    The quotation from the draft was copied from this question and verified against my copy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could have sworn i have done this somewhere - im using 2.0 right
I know I could have an attribute but that's more work than I want
I could have sworn that I saw a quick demo of new features in
I have a Double which could have a value from around 0.000001 to 1,000,000,000.000
I just wanted to see if I could have your thoughts on the design
There are many skills a programmer could have (understanding the problem, asking good questions,
In prior versions of Windows before Vista you could have a Windows Service interact
I'm writing a Java Tree in which tree nodes could have children that take
Below is my table, a User could have multiple profiles in certain languages, non-English
Why isn't Collection.remove(Object o) generic? Seems like Collection<E> could have boolean remove(E o); Then,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.