delete
-
Luc Pattyn wrote:
I wish there were an easier way
You can write pure C in a .cpp source file.
It's time for a new signature.
that is a shocking idea, probably correct, but shocking nonetheless. why would I drag the wrong extension with me? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Walkthrough: Compiling a C Program Like this link works the compiller but so i must write the code with notepad or an editor. But how can i make a new projekt in VS10 and compile it there, so as with C#. What i must do? I open a new project then ?
New Project -> Visual C++ -> Empty Project In Solution Explorer window, right click & select "Source Files" -> "Add" -> "New Item" On left side of the "Add new item" dialog, select "Code" In the file name field type "YourFileName.c" and click "Add" Write some code in the file like below and press "Ctrl + F5", you can see the output:
#include "stdio.h" int main() { int nNum = 10; char cChar = 'a'; printf("%d", nNum); printf("\n"); printf("%c", cChar); printf("\n"); return 0; }
Regards-- "Programming is an art that fights back!"
-
Choose "Empty project". When adding files, specify extension as C (actually extension doesn't matter). Now on the project properties, choose "Compile as C" option.
Best wishes, Navaneeth
I can´t chose "Compile as C" Where is that precisly?
-
I can´t chose "Compile as C" Where is that precisly?
-
New Project -> Visual C++ -> Empty Project In Solution Explorer window, right click & select "Source Files" -> "Add" -> "New Item" On left side of the "Add new item" dialog, select "Code" In the file name field type "YourFileName.c" and click "Add" Write some code in the file like below and press "Ctrl + F5", you can see the output:
#include "stdio.h" int main() { int nNum = 10; char cChar = 'a'; printf("%d", nNum); printf("\n"); printf("%c", cChar); printf("\n"); return 0; }
Regards-- "Programming is an art that fights back!"
Yes i did it so then he write: The Application "c:\Pfad..." can´t start. The System couldn´t the file. Where can i set the Compiler? I can´t set it.
-
N a v a n e e t h wrote:
set "Compile as C".
I never did that, it seems to know from the extension (as it should IMO).
N a v a n e e t h wrote:
create an empty project
ah. of course. I'll have to remember that. thanks. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
it seems to know from the extension (as it should IMO).
I don't think so. On default settings it uses C++ compiler to compile the code irrespective of what extension it is. You can see this from the output window. This will work because most of the C code is also valid on C++. When you set the "Compile as C" option, you can see adiitional compiler flag getting added to the compile command and it defaults to the C89 standard. :)
Best wishes, Navaneeth
-
N a v a n e e t h wrote:
set "Compile as C".
I never did that, it seems to know from the extension (as it should IMO).
N a v a n e e t h wrote:
create an empty project
ah. of course. I'll have to remember that. thanks. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
...it seems to know from the extension (as it should IMO).
It always has for me. I've never changed compiler options when switching between C and CPP files.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Luc Pattyn wrote:
it seems to know from the extension (as it should IMO).
I don't think so. On default settings it uses C++ compiler to compile the code irrespective of what extension it is. You can see this from the output window. This will work because most of the C code is also valid on C++. When you set the "Compile as C" option, you can see adiitional compiler flag getting added to the compile command and it defaults to the C89 standard. :)
Best wishes, Navaneeth
I now located the "compile as C" switch (project Properties/Configuration Properties/CC++/Advanced); I'm pretty sure I've never used it before. I will experiment next time I need some native code stuff. Thanks. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Luc Pattyn wrote:
it seems to know from the extension (as it should IMO).
I don't think so. On default settings it uses C++ compiler to compile the code irrespective of what extension it is. You can see this from the output window. This will work because most of the C code is also valid on C++. When you set the "Compile as C" option, you can see adiitional compiler flag getting added to the compile command and it defaults to the C89 standard. :)
Best wishes, Navaneeth
I just discovered Visual Studio 2008 Express Edition applies /TC (i.e. Compile as C code) for a C file inside a C++ project (which has the setting /TP, i.e. Compile as C++ code). So there is no need to change the setting provided the extension is correct. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Luc Pattyn wrote:
...it seems to know from the extension (as it should IMO).
It always has for me. I've never changed compiler options when switching between C and CPP files.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
No need to switch settings, see my 2 replies to nananeeth. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Luc Pattyn wrote:
I wish there were an easier way
You can write pure C in a .cpp source file.
It's time for a new signature.
Richard MacCutchan wrote:
You can write pure C in a .cpp source file.
But then your code won't be compiled as C code, in the sense that it is not pure C anymore (you'll be able to declare variables everywhere in a function for instance). If you specify the extension as .c, your file will be compiled as pure C code.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Choose "Empty project". When adding files, specify extension as C (actually extension doesn't matter). Now on the project properties, choose "Compile as C" option.
Best wishes, Navaneeth
N a v a n e e t h wrote:
actually extension doesn't matter
I don't know for the 2010 version, but for the 2005 version, if your file has a c extension, it will be automatically compiled as C code. So, the extension does make a difference.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Richard MacCutchan wrote:
You can write pure C in a .cpp source file.
But then your code won't be compiled as C code, in the sense that it is not pure C anymore (you'll be able to declare variables everywhere in a function for instance). If you specify the extension as .c, your file will be compiled as pure C code.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Cedric Moonen wrote:
If you specify the extension as .c, your file will be compiled as pure C code.
If you really like to be a dinosaur :laugh:
It's time for a new signature.
Awww... I am a dinosaur then :~ I had to do that for a project a couple of weeks ago. But I have to say that moving from C++ to C is really horrible.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Cedric Moonen wrote:
If you specify the extension as .c, your file will be compiled as pure C code.
If you really like to be a dinosaur :laugh:
It's time for a new signature.
or don't like to carry a big run-time library you don't need, e.g. in embedded systems. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
I just discovered Visual Studio 2008 Express Edition applies /TC (i.e. Compile as C code) for a C file inside a C++ project (which has the setting /TP, i.e. Compile as C++ code). So there is no need to change the setting provided the extension is correct. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
You are correct. It does automatically. Thanks for pointing that out!
Best wishes, Navaneeth