Visual Express 2005

Started by
6 comments, last by jpetrie 17 years, 6 months ago
Hi, I am using Microsoft Visual C++ 2005 Express Edition Visual C++ EE and would like to know how to create C files with it. All I see when creating a new project/source code is a C++ file. I have tried entering a C code in it and it worked but the editor does not highlight the keywords of C ( scanf, prinft etc...) . Is writing C code in C++ files the way to go ? Is there a way to highlight the C commands ? Thanks.
Advertisement
scanf, printf, etc. are not keywords, they are functions. Just as 'cout' isn't highlighted in C++. Keywords are like 'struct', and 'float'.
I don't think scanf, or printf would show up as keywords to begin with. They are function names and therefore are not highlighted. For instance I know in C++ cout isn't highlighted in the editor.

As for writing C code in C++ files: The only difference is the file extensions and, in the end, file extensions mean nothing when programming they are only used to tell the OS how to handle a particular file.
Quote:Original post by Ezbez
scanf, printf, etc. are not keywords, they are functions. Just as 'cout' isn't highlighted in C++. Keywords are like 'struct', and 'float'.


Ah! Thanks. So a C++ compiler is just as good for C.
according to the documentation,

Give your files the .c extension, for example mysource.c. The Visual C++ compiler automatically assumes that files with the .C extension are C files and not C++ files, and rejects C++ syntax and keywords (such as public, private, and class).



http://www.daniweb.com/techtalkforums/thread16256.html
this talks about setting it to "Compile as C" I think i have done the same before, now I just can't find it.
Quote:Original post by Myotis
Quote:Original post by Ezbez
scanf, printf, etc. are not keywords, they are functions. Just as 'cout' isn't highlighted in C++. Keywords are like 'struct', and 'float'.


Ah! Thanks. So a C++ compiler is just as good for C.

Not really, no. A C++ compiler is only good for C++. The major alternatives happen to come with both, but in general a C++ compiler will only compile that subset of valid C code that happens to be valid C++ code as well.

Using VS, I believe giving the source a .c extension instead of a .cpp one will result in C compilation. If not, the neccessary compiler switch is /TC.

CM
Any good C program should compile in C++, so long as it follows the rules of C++ too.
Originality is dead.
Not true. C is not C++. Don't try to make one act like the other, just because the syntax is very similar. You'll get bitten eventually.

This topic is closed to new replies.

Advertisement