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? :)

Sunius
  • 2,789
  • 18
  • 30
  • 1
    illegal instruction? are you sure you are compiling for your cpu? – PlasmaHH Jan 31 '13 at 12:40
  • @PlasmaHH I doubt it would have gotten to main with the wrong architecture. My thoughts are dud build, bad memory, bad AV software. – ta.speot.is Jan 31 '13 at 12:41
  • 2
    @ta.speot.is: If it only differs in stuff like SSE it can very well run most of the code up and into main. – PlasmaHH Jan 31 '13 at 12:42
  • 1
    @PlasmaHH You have a good point. – ta.speot.is Jan 31 '13 at 12:43
  • Here's my CPU info: http://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. – Sunius Jan 31 '13 at 12:45
  • @Sunius 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. – Christian Rau Jan 31 '13 at 12:48
  • Have you tried replacing `system("pause")` with `cin.get()`? – Nolonar Jan 31 '13 at 12:49
  • Wild stabs in the dark. Have you tried running without the debugger attached and/or do you have update 1 installed? http://social.msdn.microsoft.com/Forums/en/vsdebug/thread/418bc8fa-20d3-43e9-9494-fc8e5d3aad73 – ta.speot.is Jan 31 '13 at 12:50
  • @ChristianRau what do you suggest then? – Sunius Jan 31 '13 at 12:51
  • @ta.speot.is It crashes when run directly through .exe file as well. Update 1 is installed. – Sunius Jan 31 '13 at 12:53
  • Wow, that's one messed up system. – Lightness Races in Orbit Jan 31 '13 at 13:20
  • @ta.speot.is 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. – doug65536 Jan 31 '13 at 21:49
  • See also http://stackoverflow.com/questions/21256792/write-access-violation-on-read-instruction/21564508#21564508 – Marc Durdin Sep 09 '16 at 11:34

2 Answers2

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.

Mooing Duck
  • 64,318
  • 19
  • 100
  • 158
  • 3
    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. – Mooing Duck Jan 31 '13 at 21:15
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.

Puppy
  • 144,682
  • 38
  • 256
  • 465
  • `AMD released the third-generation Athlon, code-named "Palomino", on October 9, 2001 as the Athlon XP.` http://en.wikipedia.org/wiki/Athlon#Palomino – Lightness Races in Orbit Jan 31 '13 at 13:21
  • 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. – Puppy Jan 31 '13 at 13:23
  • 2
    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. – Lightness Races in Orbit Jan 31 '13 at 13:25
  • 1
    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. – Puppy Jan 31 '13 at 13:26
  • 4
    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. – Lightness Races in Orbit Jan 31 '13 at 13:27
  • 3
    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. – Puppy Jan 31 '13 at 13:28
  • 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. – Mats Petersson Jan 31 '13 at 13:31
  • 3
    @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. – Lightness Races in Orbit Jan 31 '13 at 13:32
  • @Basic: No, I'm saying his compiler is probably not set for that. – Puppy Jan 31 '13 at 13:34
  • Thank you! Disabling SSE2 in compiler options worked like a charm! – Sunius Jan 31 '13 at 13:45
  • 2
    @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). – Christian Rau Jan 31 '13 at 13:50
  • +1 For profound insight and deep knowledge of compiler's ability to make things worse when only wishing well ) – SChepurin Jan 31 '13 at 13:54
  • +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 LOL – Chad Jan 31 '13 at 14:02
  • @SChepurin 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. – ta.speot.is Jan 31 '13 at 22:06