What wrong with this code

Started by
37 comments, last by Tiffany Smith 20 years, 10 months ago
pretty sure void main(void) is a compiler specific piece of code... It may be widely supported by most compilers, but that doesn''t mean it works for everyone.

compiling can be a big help when debugging... :D
If only I knew now what I knew not tomorrow...
Advertisement
One reason to provide a return value from main is that for most POSIX systems (including Unix and that POSIXishness that Windows exhibits) expect an invoked program to return an exit code. This doesn''t make much sense for a GUI program, one could argue, but certainly from command line invoked programs, exit codes are useful AND expected.

If your compiler accepts a void return for main, then you have to ask yourself, WHAT value is the compiler returning for me? There''s going to be one in any and every case...

Batch and script programs are gonna be doing:

# this is pseudo code...
SomeUsefulCommandLineProgram
if (last_exit_status <> 0)
# there was an error. whoops.
else
# everything is hunky dory, continue...
end if
can you use printf in c++?
(friend) WHAT!!!!..... Are you crazy??? (me) Yes I am.
yes
An ASCII tetris clone... | AsciiRis
It''s even possible to use cout and printf in the same program, but you should call ios::sync_with_stdio(true) first.
What is better cout or printf. Also what is ios::sync_with_stdio(true), i am still somewhat new. Can you point me where i can learn more about it. Thanks
(friend) WHAT!!!!..... Are you crazy??? (me) Yes I am.
I am of the impression that printf is less buggy.
An ASCII tetris clone... | AsciiRis
quote:Original post by nobodynews
If you use printf wrong, bad things can happen. ie: printf("%d%d%f\n", 25, 10);
Really? My compiler gives a readable warning.
quote:Original post by Tiffany Smith
I am of the impression that printf is less buggy.
Perhaps you''ve been using a buggy implementation. May I suggest STLport? It seems to be widely respected.
Tiffany: I don''t believe any (important) released versions of iostream are buggy. Maybe you''re not using it right?
quote:Original post by librab103
What is better cout or printf. Also what is ios::sync_with_stdio(true), i am still somewhat new. Can you point me where i can learn more about it. Thanks


Define better . Back in Turbo C/C++ me and my friend wrote a benchmark to test the speed of both cout and printf with some simple stuff (a single line of text with a 16-bit integer value) and printf won hands down. The more variables, the more efficient printf becomes (As cout is simply recalling itself with the new variable type, while printf only gets called once no matter how many you pass to it). But, cout is probably a bit more extensive, and easy to use. I always use/used printf for any outputting, and I still use its variants for my logging systems, since it''s so easy to implement, and works perfectly fine.

This topic is closed to new replies.

Advertisement