Solved

compiling C in Visual C++

Posted on 1998-10-27
9
260 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now