Solved

compiling C in Visual C++

Posted on 1998-10-27
9
263 Views
Last Modified: 2013-12-14
i am compiling C files in MS Visual C++ 6.0
i thought that the compiler would compile .c files with a C compilers, and .cpp with a C++ compiler.  However, i just noticed that when i added some comments to the C files, i robotically used // to demarcate comments. Much to my surprise the compiler does not flag this as an error.

This is not so bad, but it makes me think that the predefined macro __cplusplus is true, when i was thinking it would be false.

is there a flag in Visual C++ that i can say to use the C compiler, not C++?



0
Comment
Question by:mickeydog
  • 5
  • 4
9 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1176278
VC uses the same compiler for both .c and .cpp files.  for .c files it dissables the C++ extensions, such as classes and templates.   I would have thought it dissables use of the // comments, but maybe not.  Or maybe they are now allowed in C.  With all the attention focused on standardizing  C++ these past few years, few people have paid attention to the fact that C was been updated and standardized as well.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1176279
note that the __cplusplus macro should be correct.  I have seen implementations where the // and / operator are used to make this work.  But they don't have to use that tecnique to make it work.  That is, the standard says that __cplusplus must be true in a C++ program and either false or undefined in a C program.  The standard don't say how that is to be accomplished.
0
 

Author Comment

by:mickeydog
ID: 1176280
well, my concern is that __cplusplus is NOT TRUE, so i guess i'm safe.

i checked Project | Settings | C/C++ | Code Generation | Calling convention and it is set to _cdecl, (not _stdcall), so that's encouraging.


0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 22

Expert Comment

by:nietod
ID: 1176281
There is a ./TC command line option (there probably is a switch somewere in the projects settigns that cooresponds to this too)  This switch makes it treat all files as C files not C++.  regardless of extension.  However, there is no indication it will do anything that the .c extensions doesn't already do for you.
0
 

Author Comment

by:mickeydog
ID: 1176282
well, my concern is that __cplusplus is NOT TRUE, so i guess i'm safe.

i checked Project | Settings | C/C++ | Code Generation | Calling convention and it is set to _cdecl, (not _stdcall), so that's encouraging.


0
 

Author Comment

by:mickeydog
ID: 1176283
well, my concern is that __cplusplus is NOT TRUE, so i guess i'm safe.

i checked Project | Settings | C/C++ | Code Generation | Calling convention and it is set to _cdecl, (not _stdcall), so that's encouraging.


0
 

Author Comment

by:mickeydog
ID: 1176284
well, my concern is that __cplusplus is NOT TRUE, so i guess i'm safe.

i checked Project | Settings | C/C++ | Code Generation | Calling convention and it is set to _cdecl, (not _stdcall), so that's encouraging.


0
 

Author Comment

by:mickeydog
ID: 1176285
i don't see that /Tc buys you anything over a file with .c as an extension either.
while looking at /Tc, i ran across /Za, which disables MS C++ language extensions.
its annoying that the extensions are enable by default!

0
 
LVL 22

Expert Comment

by:nietod
ID: 1176286
VC is really aimed at creating windows programs (Microsoft has a bias that way)  You can't create windows programs without those extensions so....

But the extensions should not matter to you.  
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question