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
Solved

compiling C in Visual C++

Posted on 1998-10-27
9
264 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

840 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