I have used the search, but cant find an answer

This is a discussion on I have used the search, but cant find an answer within the C Programming forums, part of the General Programming Boards category; everyone is telling me that void main() is wrong, thats what my teacher told us to use, so im just ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    33

    I have used the search, but cant find an answer

    everyone is telling me that void main() is wrong, thats what my teacher told us to use, so im just wondering why everyone says its wrong? all the programs i have done so far have worked with void main () so i dont get whats the problem with it

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Search the board, its in the FAQ too, and like about a zillion hits on google.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>all the programs i have done so far have worked with void main ()
    Assuming your implementation defines void main to do something sane, there's nothing wrong except for stylistic and portability issues. If, on the other hand, your implementation doesn't define void main to do something then the result is undefined behavior, where your program can and may do anything imaginable. That anything imaginable is the bad thing, it may work fine and it may rewrite your operating system. That's what's wrong with void main, you just can't be sure if it's safe, so you shouldn't use it at all :-)
    *Cela*

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >>Assuming your implementation defines void main to do something sane, there's nothing wrong except for stylistic and portability issues.

    Wrong, void main isn't and never will be c++ or c.

    http://www.research.att.com/~bs/bs_faq2.html#void-main
    Last edited by RoD; 02-12-2003 at 03:42 PM.

  5. #5
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>Wrong, void main isn't and never will be c++
    I didn't say it was C or C++, the ANSI standard states clearly that anything other than int main is undefined. However, several compilers define and accept void main, so it's not wrong for that compiler only. :-)
    *Cela*

  6. #6
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I don't care if it accepts it, that doens't make it right, because its not.

  7. #7
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>I don't care if it accepts it, that doens't make it right, because its not.
    According to the language standard, yes. I agree with you, but I don't understand the point you're trying to make. I was talking about an implementation feature unrelated to the language itself. If you want to talk about C/C++ then we can agree with each other that void main is wrong until the end of time :-)
    *Cela*

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Cela
    >>I don't care if it accepts it, that doens't make it right, because its not.
    According to the language standard, yes. I agree with you, but I don't understand the point you're trying to make. I was talking about an implementation feature unrelated to the language itself. If you want to talk about C/C++ then we can agree with each other that void main is wrong until the end of time :-)
    You are intentionally "not understanding" the point. The point is this: When teaching or learning C or C++, do not ever use underfined behaviour. Period. If you insist on thinking that undefined behaviour is ok to use, dont ever try and help anyone. End of discussion.

    It comes down to this:
    If you want to use C or C++, do not use void main. If you insist on using void main, use Java.

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>When teaching or learning C or C++, do not ever use underfined behaviour. Period.
    Once again, I agree. My point was that if the implementation defines void main, the only real problem is with portability and those who read the code. The original question was not whether to use or avoid void main, but why it's wrong. I answered that particular question without bias :-)
    *Cela*

  10. #10
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >>My point was that if the implementation defines void main, the only real problem is with portability and those who read the code. The original question was not whether to use or avoid void main, but why it's wrong.

    And you answerd WRONG. Its WRONG because its not the language! Void main has no place on these boards at all, let alone being stated as acceptable. Its never a sane solution, and its not c/C++, PERIOD.

  11. #11
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>And you answerd WRONG. Its WRONG because its not the language! Void main has no place on these boards at all, let alone being stated as acceptable. Its never a sane solution, and its not c/C++, PERIOD.
    Relax, I never said it was acceptable. I merely explained why it was wrong as well as why some consider it not to be wrong. Preaching to the choir serves no purpose, I agree with you completely except for your overreaction, which I can ignore :-)
    *Cela*

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Like I said, for those that want to learn more on this, do a search or two.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. Question 39: Quicksort vs Linear Search
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-17-2005, 11:03 AM
  3. linear search for structure (record) array
    By jereland in forum C Programming
    Replies: 3
    Last Post: 04-21-2004, 07:31 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Replies: 2
    Last Post: 11-05-2001, 01:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21