Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > c code in C++ project

Reply
Thread Tools

c code in C++ project

 
 
Steven Woody
Guest
Posts: n/a
 
      06-04-2008
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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      06-04-2008
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.
 
Reply With Quote
 
 
 
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      06-04-2008
On Jun 4, 6:21*am, Steven Woody <(E-Mail Removed)> 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?
> 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++.
 
Reply With Quote
 
Greg Herlihy
Guest
Posts: n/a
 
      06-04-2008
On Jun 3, 10:21*pm, Steven Woody <(E-Mail Removed)> wrote:
>
> 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

 
Reply With Quote
 
Tomás Ó hÉilidhe
Guest
Posts: n/a
 
      06-04-2008
On Jun 4, 6:20*pm, Greg Herlihy <(E-Mail Removed)> wrote:

> 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++.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error while trying to run project: Unable to start debugging on the web server. The project is not configured to be debugged. windows 2003 server Claude seraphin ASP .Net 12 02-15-2014 04:29 PM
How can an asp.net project by pulling in a code-behind class from another project? moondaddy ASP .Net 4 07-27-2004 08:01 AM
Store ASP.NET project files remotely, run project locally? Raterus ASP .Net 2 04-28-2004 03:30 AM
Add C# web project to VB Web project Brad ASP .Net 2 04-01-2004 02:05 PM
Error while trying to run project: Unable to start debugging on the web server. The project is not configured Ken Stealth ASP .Net 2 01-31-2004 05:46 PM



Advertisments