Solved

compiling C in Visual C++

Posted on 1998-10-27
9
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The viewer will learn how to synchronize PHP projects with a remote server 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…

728 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