I has a blag!

Pages: 123
closed account (10oTURfi)
4) Object suicide is valid (no crash, no leak, so I guess its valid)
19) lol
20) There is a difference, you can initialize structs with initializer list, but you cant do with classes
26) Why in the world would you do that?
Last edited on
I thought C++11 introduced class initializer lists.
26) Why in the world would you do that?


You might want to force a certain base class operator or something.

27a) Using system pause assumes there is a user at the keyboard anyway so I don't see how using cin.ignore() makes that any worse.
Last edited on
Nice about page:
This is an example of a page. Unlike posts, which are displayed on your blog’s front page in the order they’re published, pages are better suited for more timeless content that you want to be easily accessible, like your About or Contact information. Click the Edit link to make changes to this page or add another page.

Very informative.
Last edited on
27a) Using system pause assumes there is a user at the keyboard anyway so I don't see how using cin.ignore() makes that any worse.

Side note: I wrongly assumed that even if the input was redirected, system("PAUSE"); would still pause the program as usual. Now I wrote a test, turns out that's not true.

Edit:
4) Object suicide is valid (no crash, no leak, so I guess its valid)

Well, I'll include a C++ FAQ-Lite link for that later. I recall the FAQ says it's only safe for a special case.

20) There is a difference, you can initialize structs with initializer list, but you cant do with classes

Thanks... I'll test that, later.
Last edited on
closed account (zb0S216C)
Krofna wrote:
"4) Object suicide is valid (no crash, no leak, so I guess its valid)"

It is valid, so long as you avoid accessing the object.

Krofna wrote:
"20) There is a difference, you can initialize structs with initializer list, but you cant do with classes"

You can use the initialiser-list on both structures and classes, so long as they are POD types. C++0x, however, has the std::initializer_list type that allows non-POD types to support initialiser-list initialisation.

"because a “plain” delete won’t do."

Worst answer to-date.

Worst FAQ I've read :)

Wazzak
#4 is quite common in COM. All COM objects written in C++ do delete this; when their reference count goes down to zero as long as it was a heap object and etc. etc. etc.
closed account (1yR4jE8b)
I recall the FAQ says it's only safe for a special case.


You are correct, it's only when using "placement new" allocation.

http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10
Last edited on
27a. Why do some people seem to hate me for using system("PAUSE");?
It’s a pet peeve that makes them feel superior to you. It is bad practice to use system() calls in production code.

So glad you have such a high opinion of your own opinion.

I used to think as you did about the validity of system("PAUSE") -- you can find a snippet over at Daniweb where I post if (!system( "clear" )) system( "pause"); or somesuch for homework stuff.

Since then I've taken a good number of university courses on pedagogy and computer security. The result is that I better understand the implications of teaching newbies to do something the wrong way, particularly when it is just as simple to do it the right way at the start.
The result is that I better understand the implications of teaching newbies to do something the wrong way, particularly when it is just as simple to do it the right way at the start.

The need to pause is wrong by itself. Highlighting this, is what the goal of question 27b was.

So both methods serve a wrong purpose. It's only that system("PAUSE"); makes more sense, is shorter and more obvious.

Perfect for homework stuff. Where the security implications aren't as prevalent.
If you are trying to execute your program outside the IDE, then I would call it "production code".
Change your IDE or learn to use it (probably just setting a flag).

¿Why do you do homework?
No, I'm with Duoas, it's pretty obvious what std::cin.get(); means.
closed account (zb0S216C)
Catfish2 wrote:
"The need to pause is wrong by itself."

I agree. The CPU could be doing something productive while it's waiting for the user. Eventually, though, the CPU will give way to other processes that require its cycles, and will break from the "waiting game", as if to say, "Screw this - I'm off; bye!"

Only when the user actually enters something will the CPU return to the program, as if to say, "Finally!"

Wazzak
Last edited on
That's not how multitasking works on modern OSes. When you request input or output (from anything), the scheduler makes a note of it, sends the request to the right place, and then puts the process to sleep. It switches to the next process immediately. The program only gets woken up when (1) the I/O is ready and (2) it's the process's turn to run. The idea is that the CPU should never be idle. In practice, it often is (look at the "System Idle Process" on Windows), but that's only when it has nothing else to do.
We've already rehashed PAUSE-ing and its issues before, and why it is wrong. There's a big sticky at the top of the Beginner's Forum all about it.

The arguments that
It's only that system("PAUSE"); makes more sense, is shorter and more obvious.
are all incorrect. It never makes more sense to spawn extra processes to wait on user input. And something like PressAnyKey(); is just as short and simple.

Perfect for homework stuff. Where the security implications aren't as prevalent.
What you are saying is that security considerations are irrelevant when teaching programming. I think that is a very dangerous attitude to have. Teach someone to do something dangerous and it takes a significant amount of effort to unteach.

Basically you are complaining that learning to do something the right way is, for reasons not yet given, more difficult and less productive than learning the wrong way. Boo hoo, I've got to type an extra few characters to do it. Boo hoo, it might take me a little longer to understand how it actually works.

Bull. It is no different than teaching students to type int main( int argc, char** argv ) instead of void main() -- except that it is correct.

[edit] I had to learn this too. And I think it disingenuous of you to label me as getting some sort of ego kick out it.
Last edited on
@chrisname - std::cin.get(); is not good for pausing because it only waits if there is nothing to read from std::cin and no error flags are set. That's very different from how system("PAUSE"); works.

@Duoas - from where can I get this PressAnyKey() function?


Last edited on
I understand system("PAUSE"); is bad, but it brings up a question. How would you go about making a program that runs in the background to monitor something while launching another program that it is monitoring? I've been told system("/program/location") or would that be something you would want to script? For example, just an example for playing devil's advocate, say you make a game, but you make a background app that monitors it so when you click the shortcut it boots the background application which starts monitoring and starts the game. While that would be a waste of time as you could just code log outputs into the code and circumvent multiple applications running for just one thing it is an example I thought of when I first learned about system() and how bad it is.
Basically you are complaining that learning to do something the right way is, for reasons not yet given, more difficult and less productive than learning the wrong way. Boo hoo, I've got to type an extra few characters to do it. Boo hoo, it might take me a little longer to understand how it actually works.

Since when is the right way about using a feature in a way that it was never meant to be used?
cin.ignore() has the purpose of ignoring characters. Not pausing the program. You keep bringing up security; there's really not much more harm system() can do... if cmd.exe is already compromised, duh.

[edit] I had to learn this too. And I think it disingenuous of you to label me as getting some sort of ego kick out it.

Boo hoo, as you say.
Last edited on
I don't want to get too much into the flame but I have to say that system("pause") won't even work on my computer and it wouldn't work in a homework solution since the result is likely to be expected to work on a Unix shell (at least this happens in my university).
Pages: 123