Tuesday, July 14, 2009

Does a c source code run on visual c++ compiler?

does a c source code run on visual c++ compiler?

Does a c source code run on visual c++ compiler?
In general, yes...





C++ is a superset of C... The name is supposed to be a pun! (One better than C... get it?)





There are always slight variations between compilers, so some minor tweaking MIGHT be needed; but usually they just run as-is!
Reply:if you compile your code as a console app, it should be no problem. to do that, just create a new project and select console application, and a blank application. then just import your code to the new app.
Reply:In general, you can use a C++ compiler to compile C programs. C++ is an extension of C. Think of it as a standard C compiler with additional support that lets it parse and compile object-oriented source statements. C++ source code looks very similar to Java.





Whether your programs will compile or not will depend on how old your version of Turbo C is. I have used Turbo C 1.5 for DOS since I first bought it in the early 1990s. In that version, an integer (int) is only two bytes. I've never used Visual C++, but I'm sure it uses 4-bytes as the default size for an int. The interfaces to C library routines have changed a bit too over the years. I've had mixed results compiling some of my old Turbo C 1.5 programs using gcc on Linux.





Good luck!
Reply:Visual C++ also comes with a C compiler. This is generally true for all C++ compiler sets. THey are usually both a C and C++ compiler combined.





You may have to modify your Turbo C code to work on Visual C++. As long as you use portable standard C code, you're good, but if you relied on Turbo C proprietary extensions, you're in trouble.





I can't believe how many people repeat the same mistake, so to correct others:





@N2FC:


In general, you don't know. It could be minor tweaking or major code rewriting.





@CinderBlock:


No, C++ is not C extended. It's an entirely different language. No, C++ isn't just C with classes. Clearly, you have never heard of templates and generic code.





If you wrote proper code, it shouldn't matter what the size of an int is, right?





People, please look at http://david.tribble.com/text/cdiffs.htm . If you think non-trivial C code works as is on C++ compilers, you are mistaken.


No comments:

Post a Comment