473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

c code in C++ project

Hi,

I usually write c code in .c files and use c compiler to compile
them. In this new project, my team member prefer to write c code
in .cpp and use c++ compiler to make them. Which method is better?
In particularly, the compiler is gnu gcc and g++, our OS is linux.

Thanks.

-
narke
Jun 27 '08 #1
6 1125
Steven Woody wrote:
Hi,

I usually write c code in .c files and use c compiler to compile
them. In this new project, my team member prefer to write c code
in .cpp and use c++ compiler to make them. Which method is better?
C and C++ are different languages. A lot of legal C will not compile as
C++.

Compile each languages with its correct compiler, otherwise you end up
with what Alf said; all C++ code.

--
Ian Collins.
Jun 27 '08 #2
Steven Woody <na********@gmail.comkirjutas:
Hi,

I usually write c code in .c files and use c compiler to compile
them. In this new project, my team member prefer to write c code
in .cpp and use c++ compiler to make them. Which method is better?
Define "better".

If the code is in .cpp and compiled by c++ compiler, then it's not a C
project any more. It does not follow exact C rules (though only in some
obscure language corners), it might easily become contaminated by some C++-
isms so it does not compile in C any more, and it does not use a
standardized C ABI (thus it cannot be linked to other C client code modules
or C++ code compiled by another C++ compiler/version). Other than that, the
method seems to be fine, one just should not pretend this is C.

My question is why do you use C at all? What is it that you can make in C,
and not in C++?

Regards
Paavo
Jun 27 '08 #3
Paavo Helde <no****@ebi.eekirjutas:
My question is why do you use C at all? What is it that you can make
in C, and not in C++?
Oops, forgot to mention this is a *rhetoric* question - don't want to
start yet another language war!

Paavo
Jun 27 '08 #4
On Jun 4, 6:21*am, Steven Woody <narkewo...@gmail.comwrote:
Hi,

I usually write c code in .c files and use c compiler to compile
them. *In this new project, my team member prefer to write c code
in .cpp and use c++ compiler *to make them. *Which method is better?
In particularly, the compiler is gnu gcc and g++, our OS is linux.

Call your C files ".c" and your C++ files ".cpp". Your IDE "Integrated
Development Environment" should use the appropriate compiler for each.

You should _not_ use a C++ compiler to compile C code, mostly because
there's plenty of legal C code that won't compile with a C++ compiler.
Consider the following:

void Func(const i) /* Error implicit int */
{
int *parr[10];

int try; /* Error keyword used as variable name */

for (try = 0; try != 10; ++try)
{
parr[try] = malloc(sizeof(int));

if (parr[try]) *(parr[try]) = val;
/* Error implicit conv from void* to int* */
}
}

You should REALLY dissuade your collegue from compiling C code as C++.
Jun 27 '08 #5
On Jun 3, 10:21*pm, Steven Woody <narkewo...@gmail.comwrote:
>
I usually write c code in .c files and use c compiler to compile
them. *In this new project, my team member prefer to write c code
in .cpp and use c++ compiler *to make them. *Which method is better?
In particularly, the compiler is gnu gcc and g++, our OS is linux.
One of C++'s design goals was to be a "better 'C' than 'C'" - so, in
fact it does make sense to write in C++ - the kind of program that one
might otherwise write in C. Or to put it another way: even programs
that are not by nature object-oriented, can still take advantage of C+
+'s other features. For example, a C++ program use inline functions,
function templates or const variables in places where a C program
would use a macro.

Greg

Jun 27 '08 #6
On Jun 4, 6:20*pm, Greg Herlihy <gre...@mac.comwrote:
One of C++'s design goals was to be a "better 'C' than 'C'" - so, in
fact it does make sense to write in C++ - the kind of program that one
might otherwise write in C. Or to put it another way: even programs
that are not by nature object-oriented, can still take advantage of C+
+'s other features. For example, a C++ program use inline functions,
function templates or const variables in places where a C program
would use a macro.

C++ took C and added more features to it, so it's better. The only
problem with C++ is that its added complexity adds considerably to the
complexity of its compiler. This gives rise to two issues:
1) The unavailability of C++ compilers
2) Bugs in C++ compilers

If I'm programming something simple then I'll go for C so that it's
more portable. If I'm programming for a micrcontroller, then I've no
choice but to go for C because there isn't a C++ compiler available.

If I'm programming a GUI application for Windows, Linux, Mac, etc.,
then I'll go for C++.
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Russ | last post by:
Hello. I have a very large business application written all in VC++ and MFC. Now I want to interface some of it to the web. I have VS.NET2003 and have been studing walkthroughs and documentation...
7
by: Dan | last post by:
I'd like to have a set of more-or-less common code which I want to use for both desktop and smart device projects. I have two questions: 1. How can I set up conditional compile directives for...
6
by: Vaclav Jedlicka | last post by:
Hi all Is it possible to create an ASP.NET project from code? Thanks in advance Vaclav
6
by: Peter Row | last post by:
Hi, Can someone give me a set of steps for an ASP.NET project (well actually its just a VB.NET class DLL that implements HttpHandler) that will work when moved to another developers machine? ...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
16
by: lawrence k | last post by:
I've made it habit to check all returns in my code, and usually, on most projects, I'll have an error function that reports error messages to some central location. I recently worked on a project...
6
by: Larry Bud | last post by:
Been working with .net 2 since January, and am in the middle of my first large project. It's becoming obvious that one must organize their code well in a large project to make maintenance...
3
by: Iluvatar | last post by:
Hi, last week our project upgraded from vs.net 2005 to vs.net 2008. Our project still uses framework 2.0, because the deployment servers are not 3.x ready yet. Everything so far while migrating...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.