Thread: 2 Noobish Questions from a 2nd Day Learner

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> there is no guarantee the system or the compiler will place return 0 on success.
    The guarantee is in the C++ standard. It is not undefined.

    Bucket, don't worry about the extra conversation taking place here. If you found a way to pause your program on your own, then use that way, it is fine. If you are curious and want to look at other ways, read the FAQ and search the forums, there have been quite a few similar discussions about the good and bad of system("pause"), cin.get(), and the other options. At this point it really doesn't matter what you choose, so only pay attention to that issue if you're curious.

    As far as '\n' versus endl, that really doesn't matter either. It is excellent that you want to use the proper technique when programming, but in these cases almost all options mentioned are perfectably acceptable and widely used.

  2. #17
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Desolation
    After searching on Bjarne Stroustrup's website (which I consider a good source), I will prove you wrong.

    http://www.research.att.com/~bs/bs_faq2.html#void-main
    I'm honestly not sure if Stroustrup didn't over-simplified that statement. There is absolutely no requirement for an operating system to use 0 as the return of a successful execution. Maybe I'm seeing this all wrong, but some OS can for instance use 1 instead. Can't it? Would there be the need to have EXIT_SUCCESS defined otherwise?

    However, as Daved mentioned (if I understood your comment, Daved) it seems to be a standard requirement for the compiler to define behavior in the absence of a return statement. I didn't know that.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #18
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >There is absolutely no requirement for an operating system to use 0 as the return of a successful execution.
    You're confusing the operating system with the C++ implementation. An exit value of 0 means success. When a return statement or exit call is not present, 0 is used implicitly.

    >Would there be the need to have EXIT_SUCCESS defined otherwise?
    As 0 is required to be interpreted as success when terminating the application, EXIT_SUCCESS is almost always defined as 0. It's there primarily for symmetry with EXIT_FAILURE, whose value is not specified.
    My best code is written with the delete key.

  4. #19
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Ok. That explain it. I was i8ndeed confusing the two thinking that one was dependant on the other. Thanks.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 35
    Last Post: 01-31-2008, 06:01 PM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  4. debug program
    By new_c in forum C Programming
    Replies: 3
    Last Post: 03-18-2002, 11:50 PM
  5. Simplified code
    By soonerfan in forum C Programming
    Replies: 2
    Last Post: 12-05-2001, 03:50 PM