Visual C++ 2012 cout crashes during run time
Asked Answered
L

2

6

I decided to try Visual Studio 2012 Express today. First thing to do was to write "Hello world!" application, however, I couldn't make it work. I created a Windows console application project, wrote standard code and it resulted in a run-time error.

Here's my code:

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;

    system("pause");
    return 0;
}

Looks like something is broken (maybe I missed something?). It gets a runtime error at line 7:

http://img443.imageshack.us/img443/7497/coutbroken.png

Any help please? :)

Lorineloriner answered 31/1, 2013 at 12:36 Comment(13)
illegal instruction? are you sure you are compiling for your cpu?Mica
@Mica I doubt it would have gotten to main with the wrong architecture. My thoughts are dud build, bad memory, bad AV software.Agamogenesis
@ta.speot.is: If it only differs in stuff like SSE it can very well run most of the code up and into main.Mica
@Mica You have a good point.Agamogenesis
Here's my CPU info: img837.imageshack.us/img837/6698/cpus.png Do you really think my CPU does not support cout? I would have a hard time believing it.Lorineloriner
@Lorineloriner That wasn't what he meant. In the end no CPU supports cout (whatever this means, anyway). He's more after the fact that you might be compiling your program for an architecture different from the one you're trying to run it on.Clannish
Have you tried replacing system("pause") with cin.get()?Zone
Wild stabs in the dark. Have you tried running without the debugger attached and/or do you have update 1 installed? social.msdn.microsoft.com/Forums/en/vsdebug/thread/…Agamogenesis
@ChristianRau what do you suggest then?Lorineloriner
@Agamogenesis It crashes when run directly through .exe file as well. Update 1 is installed.Lorineloriner
Wow, that's one messed up system.Meaghan
@Agamogenesis if they enabled the latest architecture in the CRT startup code, there would be no point in changing the architecture on the compiler command line since the startup code is compiled already. You would then need several versions of the startup code, and it wouldn't help performance enough to matter.Surcease
See also #21257292Esbjerg
H
13

Your CPU is in urgent need of being junked. Your compiler is probably set for a CPU from this century. You may be able to disable the newer instructions like SSE2.

Higdon answered 31/1, 2013 at 13:20 Comment(14)
AMD released the third-generation Athlon, code-named "Palomino", on October 9, 2001 as the Athlon XP. en.wikipedia.org/wiki/Athlon#PalominoMeaghan
Well, I think that the general point still stands. The thing is from before desktop CPUs were multi-core. THere's a perfectly good chance VS is emitting SSE2 code.Higdon
I don't see any reason to presume that Visual C++ and std::cout is incapable of being run on a 2001 Athlon. But, yes, perhaps some configuration is required.Meaghan
It's not incapable, probably, but it can certainly be set that way, and the real question is whether or not it defaults to that way.Higdon
And my point is that "Your CPU is destined for the junk heap" is ludicrous. Not everybody replaces every system every two years. There is, in general, no actual need to.Meaghan
There's a very big difference between "Every two years" and "Twelve years"- especially considering the gains Intel made over AMD in those years. The performance of an Athlon XP is far, far below what any current program will target. I'm surprised that VS will even execute, and isn't compiled for SSE2 itself.Higdon
But then setting the compiler to compile for something that is old is probably a good idea - or even using an older version of compiler. But I'm pretty sure you can still compile for "486" or "Pentium(Pro)" or some such, which should work on any processor.Fabron
@DeadMG: You're surprised that VS will execute? Are you serious? Do you realise how many computers still run XP? And how much code within XP dates back to the Windows 98 days? You seem to have this bizarre idea in your head that programs are, in general, backward compatible for very short periods of time.Meaghan
@Basic: No, I'm saying his compiler is probably not set for that.Higdon
Thank you! Disabling SSE2 in compiler options worked like a charm!Lorineloriner
@Basic No, he's just saying that the compiler is configured for the wrong machine (which in fact deserves a +1), though worded a bit ridiculously and overgeneralizing (which might deserve a -1).Clannish
+1 For profound insight and deep knowledge of compiler's ability to make things worse when only wishing well )Adrea
+1 Hhaha for jackass reponse, that turns out to be correct about SSE2, now I've got to convert the programs I make so they run on Athon XP chips LOLDrucilladrucy
@Adrea Yeah me too, we have some Visual C++ 2008 projects that have been migrated between the various versions of Visual C++ over the years and some point soon we were going to recreate them from scratch, in VS2012, with nice clean settings. I'll be keeping an eye out for this setting now.Agamogenesis
H
17

Since DeadMG's answer is rude and vague:

Visual Studio 2012 targets SSE2-enabled machines by default, which includes virtually any processor made in the last ten years. Unfortunately, your AMD Athalon XP is twelve years old, and does not have SSE2, so to run your programs, you'll need to disable those instructions.

On Visual Studio 2008 (you don't have this) the way was to open the "Solution Window", right click the project -> Properties -> Configuration Properties -> C++ -> Code Generation -> Enable Enhanced Instruction Set. Set this to "Not Set".

You have Visual Studio 2012 (I don't), so your instructions will differ. The official instructions are: Open the Property Pages dialog box for the project, Select the C/C++ folder, Select the Code Generation property page, and Modify the Enable Enhanced Instruction Set property. source.

Headrace answered 31/1, 2013 at 21:13 Comment(1)
If DeadMG wishes to copy this info into his answer and/or make his less rude, I'll delete this one. My goal is to help, not steal rep.Headrace
H
13

Your CPU is in urgent need of being junked. Your compiler is probably set for a CPU from this century. You may be able to disable the newer instructions like SSE2.

Higdon answered 31/1, 2013 at 13:20 Comment(14)
AMD released the third-generation Athlon, code-named "Palomino", on October 9, 2001 as the Athlon XP. en.wikipedia.org/wiki/Athlon#PalominoMeaghan
Well, I think that the general point still stands. The thing is from before desktop CPUs were multi-core. THere's a perfectly good chance VS is emitting SSE2 code.Higdon
I don't see any reason to presume that Visual C++ and std::cout is incapable of being run on a 2001 Athlon. But, yes, perhaps some configuration is required.Meaghan
It's not incapable, probably, but it can certainly be set that way, and the real question is whether or not it defaults to that way.Higdon
And my point is that "Your CPU is destined for the junk heap" is ludicrous. Not everybody replaces every system every two years. There is, in general, no actual need to.Meaghan
There's a very big difference between "Every two years" and "Twelve years"- especially considering the gains Intel made over AMD in those years. The performance of an Athlon XP is far, far below what any current program will target. I'm surprised that VS will even execute, and isn't compiled for SSE2 itself.Higdon
But then setting the compiler to compile for something that is old is probably a good idea - or even using an older version of compiler. But I'm pretty sure you can still compile for "486" or "Pentium(Pro)" or some such, which should work on any processor.Fabron
@DeadMG: You're surprised that VS will execute? Are you serious? Do you realise how many computers still run XP? And how much code within XP dates back to the Windows 98 days? You seem to have this bizarre idea in your head that programs are, in general, backward compatible for very short periods of time.Meaghan
@Basic: No, I'm saying his compiler is probably not set for that.Higdon
Thank you! Disabling SSE2 in compiler options worked like a charm!Lorineloriner
@Basic No, he's just saying that the compiler is configured for the wrong machine (which in fact deserves a +1), though worded a bit ridiculously and overgeneralizing (which might deserve a -1).Clannish
+1 For profound insight and deep knowledge of compiler's ability to make things worse when only wishing well )Adrea
+1 Hhaha for jackass reponse, that turns out to be correct about SSE2, now I've got to convert the programs I make so they run on Athon XP chips LOLDrucilladrucy
@Adrea Yeah me too, we have some Visual C++ 2008 projects that have been migrated between the various versions of Visual C++ over the years and some point soon we were going to recreate them from scratch, in VS2012, with nice clean settings. I'll be keeping an eye out for this setting now.Agamogenesis

© 2022 - 2024 — McMap. All rights reserved.