views:

65

answers:

3

I appreciate the differences are negligible, but im doing some number crunching and so i want to use C. Ive just created a project in VS2010, chosen a C++ project and written some C. All executes fine, but

is this being created and executed in the fast(er) C compiler or the C++ because its a C++ project?

How can i specify that the code i wish to write is actually C and to be compiled and run as C?

+5  A: 

The Visual Studio C++ compiler will treat all .c files as C language files and compile them as such.

Additional reference:

By default, the Visual C++ compiler treats all files that end in .c as C source code, and all files that end in .cpp as C++ source code. To force the compiler to treat all files as C regardless of file name extension, use the /Tc compiler option.

http://msdn.microsoft.com/en-us/library/bb384838.aspx

JTA
+1 about the /Tc compiler option, which I feel like I should have known already...
Andrew Barber
A: 

You are just being silly now. C is not guaranteed to be faster than C++ in any way - it's all compiled to native machine instructions in the end. If you want a true performance leap you should use another compiler, Intels for example, or use the GPU or something like that.

Alex
A: 

What will actually give you more speed is to use Intel's compiler, which is available as a plugin. The real-world differences are significant, especially for number crunching. The difference between C and C++ is dubious.

Here's a good place to start: link text

Since you're number crunching, you should consider using SIMD extensions, if possible. Using SIMD on Intel's compiler, vs. straight MS C compiled code, will give you some serious gain.

IanC
As Alex said, the GPU is another option. You can use OpenCL or Microsoft's Direct Compute here. As for speed, with the right GPU, you're into the supercomputing realm... on a pc.
IanC