|
From: Jonathan W. <jon...@gm...> - 2007-07-16 08:28:46
|
Hi,
Indeed, using system("pause") at the end of your program isn't too much of a
problem, however, I don't agree that it is better than getchar().
> Using system("pause") to stop execution to aid in debugging an application
makes a lot of sense. Especially if you choose not to use gdb to debug your
code.
What sense does it make? If there is a good reason, maybe you can convince
me. I don't see what link to gdb there is, since the result of both
alternatives is the same.
> It is in the language for a reason.
Indeed, system() is in the language to allow a program to easily call
another without all the fork/exec whatnot, when it isn't necessary. But this
only makes sense when the other program called has some kind of added value,
such as performing a _non-trivial_ operation
Likewise, PAUSE is in the O.S. for a very good reason: allowing batch files
to wait for the user.
I am not against system(), nor PAUSE; but I don't think using them together
to perform the same thing as getchar() makes sense.
> Jonathan my advice to you is to understand how to use the language
efficiently [...]
I believe you were talking to Arpit Jain here rather, but I shall suppose it
was for me, and so:
I think I have learned in my past years of experience how to use C quite
efficiently. I am surely no guru, but I'm pretty content, I also believe I
can still learn.
Indeed, people may 'make a religion' of (not) coding some way or other, but
in this case it's different; the system(pause) issue has a backing
arguments, not just "BECAUSE you don't use it!"
I also have confidence in the designers and community. Microsoft included
PAUSE with good reason. The designers included system() for a reason, they
included the 'goto' keyword for a reason (and no, I'm not going to develop
on that further than it should be used when more structured control is not
efficient). On the other hand, 'system("pause")' isn't part of the standard
or the language but is a confluence of two worlds, and the language has an
alternative to it.
Every part of the (language, tools, etc) has indeed it's pros and cons, and
we should all learn to know them and work with them.
In this case, the pros are ['is does what it says'], and the cons are ['it
is totally inefficient']. My choice is quickly made.
Arpit Jain, your choice is in your hands. I have used system("pause") many
times in the past, and it didn't bite. Just bear in mind the problem it
could be, especially when using system() for other things.
Adam, I would be honoured to share your knowledge.
Yours,
Jonathan
On 7/14/07, Adam Jones <aj...@i-...> wrote:
>
> >>There are two global solutions:
> >>a. make your program wait for a keypress before exiting
> >>b. open a console, go to the folder, and run the program from there.
>
> There is a third choice and that is to use the system("pause") it is very
> easy to use and very appropriate for what he is doing in the Hello world
> program. He must make sure that he includes the <cstdlib> header.
>
> >>a. is is easier for you to use while developping, since you can start
> the
> prog from DevC++ and see the result.
>
> >>A correct way of doing this is to call getchar();
> >>this will try to read a char from the input, and will wait until it gets
> one. much better.
>
> >An EVIL way is to call system("pause"); You can read why here:
> http://www.gidnetwork.com/b-61.html
>
> I read this link along with others that this person posted. Having a
> system("pause") call at the end of the program poses no problem, because
> the
> next call is to exit. Especially in a HELLO WORLD program. Using
> system("pause") in a release version would not make sense. Using
> system("pause") to stop execution to aid in debugging an application makes
> a
> lot of since. Especially if you choose not to use gdb to debug your code.
> It is in the language for a reason. Use it when it is appropriate.
>
> >>Jonathan
> >>On 7/13/07, arpit jain <arp...@gm...> wrote:
> >>im new 2 programing & i have been trying to learn C, & for that i
> started
> using bloodshed dev c++5.0 but what im not getting is when i run the
> program
> the software doesnt show >>the result but makes an application file (DOS
> based) for e.g. that HELLO WORLD program's output just gets flashed in the
> command prompt which im myself unable to see properly >>as it flashes
> hardly even for a second. could u pls. help me on this.........????
>
> Jonathan my advice to you is to understand how to use the language
> efficiently. You will find people telling you never to program this way or
> never to program that way. But they make a religion out of it. I have
> confidence in the designers who developed C\C++, and the ANSI community
> that
> oversees the ANSI standard for C\C++. You use what is best for the problem
> you are trying to solve. Every keyword/STL function, etc has it's pros and
> cons. You need to understand what those are and program accordingly.
>
> -Adam Jones
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
--
<Morpheus> linux, c'est une question de VI ou de MORE
|