Solved

compiling C in Visual C++

Posted on 1998-10-27
9
257 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

758 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

19 Experts available now in Live!

Get 1:1 Help Now