void main()

I see a lot of discussions about void main()

If void main() is so bad, then why does it exist in the first place?

Sorry for bad English
Last edited on
There are many things in C++ that can be "bad", but they do exist. Knowing overlay of class you can access its private members by going through the pointer to the beginning of the class, although it's something that should be punishable by long tortures.
You can allocate memory with new and don't free its memory.
You have tons of undefined things, which you still can do.

The point of programming is creating both good, fast and readable code(some would even argue that whole point is creating the readable code, that is fast only as side effect). You can't fix some things, but you can do your best to make both yours and others more comfortable reading your code, by doing your best.
@ OP: void main() is wrong because the C++ ISO standard explicitly states that main must return an integer when it finishes executing. It is not bad or evil think of it as being grammatically wrong.

MatthewRock wrote:
You have tons of undefined things, which you still can do.

Undefined does not mean disallowed those two definitions are distinctly different. It means that in regards to the condition that is being referred to, the C++ standard does not dictate what the behavior will be so any behavior observed from that code should not be relied on. In most cases the behavior is defined by some other standard of some other aspect of the system (it is in reality a finite state machine after all) but that behavior varies and is outside of the scope of the C++ documentation. The endianness of memory is one example; C++ doesn't care about what endianness the system architecture uses. But since it allows for DMA the programmer must be aware that the behavior of code which assumes that bytes are mapped a specific way is not dictated by the code they write.
Topic archived. No new replies allowed.