I wrote a simple C++ program that asks for a filename, opens that file and prints its contents to the screen. Finally, it closes the file.
I wrote the program using G++ on OS X and it works fine under that operating system. However, when I attempt to run the program in Windows XP sp3, I receive an error message. That error message is: "The NTVDM CPU has encountered an illegal instruction."
I believe this error is related to the fact my program is 16-bit and Windows XP desires a 32-bit program.
No. The compiler should generate 32-bit code unless specifically asked (assuming it's possible) to produce 16-bit code. C/++ is system-independent, so it has no word size.
My guess is that you either tried to run the MacOS executable on Win32, or you produced a buffer overrun by entering more that 11 characters into 'filename' (the twelfth character is '\0'). 8.3 file names can be up to 12 characters long, so I think this is very likely.
Fix: make 'filename' be (at least) 256 characters long.
Also, use [code][/code] tags to make your code more readable when posting.
Yes, that's exactly what I feared from the wording of your post.
1. PowerPC is an architecture separate from x86. Not only does it have a different instruction set - which, by itself, is already enough - it doesn't even have the same endianness: on an x86, the physical representation of a 16-bit integer with a value of 4660 is 34 12, while on the PowerPC it's 12 34
2. If the above alone wasn't enough, MacOS X is based on the Mach kernel, derived from BSD. This means that neither it uses the PE (Portable Executable) format Windows uses, nor does it use the same system calls used by Win32.
In other words, there's no way to directly run a program compiled for any version of MacOS X - be it x86 or PowerPC (chuckle) - on any version of Windows.
Luckily for you, you wrote your program in C++, which is a system-independent language. All you need to do is a) install a C++ compiler on the Win32 installation and recompile your code, or b) install a C++ cross-compiler for Win32 on MacOS and recompile your code for Win32.
This is interesting, when I did C++ programming on a PPC Mac (about... 4 years ago now), it always forced me to include an OSX-specific library. I forget its name, but if I did not #include it, the compiler would not do its job.
You do not seem to be having these difficulties, mjwhite1. May I ask (and hope for a satisfactory response ;) what version of OSX, what Processor and what version of XCode you are using?
I'm not after your computer, in case you fear that >_> It's just my insatiable curiosity, forcing me to ask these questions.
I am using OS X 10.4.11 with a 1.42CHz PowerPC G4.
I am not using XCode because I find it to be user-unfriendly when it comes to writing short programs. I AM using an editor called Jedit (www.jedit.org), which is mostly used for Perl scripting. I find it to be very useful for writing short C++ programs.
To compile my programs, I am using G++, which I call from a terminal window. Since I use antiquated header files, I use the -wno-deprecated flag.
Basically, my command is as follows: g++ -wno-deprecated -o file_name /path/to/program/program.cpp
BTW:
Thanks for the information Helios, I sincerely appreciate it!