Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Porting from C to C++

Reply
Thread Tools

Porting from C to C++

 
 
rockstar
Guest
Posts: n/a
 
      05-18-2006
Hi all,

I'm one of those wiz kids who knows a bit about all the main
programming languages (C, C++, Java, PHP, Python, etc...) but none of
them super good. I'm actually working as a software developer now, and
am working with PHP, skills are much improved, and I'm going to school
and learning Java, and doing C++ out of a bunch of books, mostly "Teach
Yourself C++ in 24 Hours" which seems to be helping a lot. I've hopped
on a few open source projects so that I can get exposure with the
language and learn the problem solving by actually doing it.

One of the first things I need to do is port a C program (actually a
pretty simple, single program) to C++. As I look at the code, I
understand what's going on. My biggest question is "What are some of
the biggest differences between C and C++" I'm talking syntax, etc.
I'm gonna have to port this whole program soon, and would like to get
the best C++ guys to warn me about pitfalls, etc. I'm using linux and
g++. Apparently, g++ compiles c as well so I figure I'll use that for
compilation.

Your input is appreciated, especially because I'd like to become
strong with C++.

Paul
http://eventuallyanyway.com

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      05-18-2006
rockstar wrote:
> I'm one of those wiz kids who knows a bit about all the main
> programming languages (C, C++, Java, PHP, Python, etc...) but none of
> them super good.


I am guessing you meant "none of them well enough."

> I'm actually working as a software developer now,
> and am working with PHP, skills are much improved, and I'm going to
> school and learning Java, and doing C++ out of a bunch of books,
> mostly "Teach Yourself C++ in 24 Hours" which seems to be helping a
> lot.


Check out www.accu.org (their book review section) to see what other
books are recommended.

> I've hopped on a few open source projects so that I can get
> exposure with the language and learn the problem solving by actually
> doing it.


Not a bad idea.

> One of the first things I need to do is port a C program (actually a
> pretty simple, single program) to C++. As I look at the code, I
> understand what's going on. My biggest question is "What are some of
> the biggest differences between C and C++" I'm talking syntax, etc.


Have you tried looking on the web or in the news archives for that?

> I'm gonna have to port this whole program soon, and would like to get
> the best C++ guys to warn me about pitfalls, etc. I'm using linux and
> g++. Apparently, g++ compiles c as well so I figure I'll use that for
> compilation.


Pitfalls? Not too many. The simplest way to start is to rename your
files from .c to .C (or to .cxx, to .cc, to .cpp, etc.) to differentiate
them from what they were, and to compile them using a C++ compiler. If
it compiles, link, if links, run. If it does what you need, you've done
what you needed to do. If it breaks somewhere, figure out why and fix
it accordingly. That's all.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      05-18-2006
rockstar wrote:
> One of the first things I need to do is port a C program (actually a
> pretty simple, single program) to C++. As I look at the code, I
> understand what's going on. My biggest question is "What are some of
> the biggest differences between C and C++" I'm talking syntax, etc.
> I'm gonna have to port this whole program soon, and would like to get
> the best C++ guys to warn me about pitfalls, etc. I'm using linux and
> g++. Apparently, g++ compiles c as well so I figure I'll use that for
> compilation.


Don't let syntax fool you: C and C++ are two different languages. Even
if two languages use the same vocabulary, idioms may be completly
different.

"Porting" a C program to C++ is an easy task if you only want to
compile it (well written C code compiles on a C++ compiler, unless C++
keywords are used). However, if you want to use design patterns, idoms
and object-oriented features, you pretty much have to start from
scratch.

Converting "printf" to "std::cout" is not all there is to do!


Jonathan

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-18-2006
Jonathan Mcdougall wrote:
> rockstar wrote:
>
>> One of the first things I need to do is port a C program (actually a
>>pretty simple, single program) to C++. As I look at the code, I
>>understand what's going on. My biggest question is "What are some of
>>the biggest differences between C and C++" I'm talking syntax, etc.
>>I'm gonna have to port this whole program soon, and would like to get
>>the best C++ guys to warn me about pitfalls, etc. I'm using linux and
>>g++. Apparently, g++ compiles c as well so I figure I'll use that for
>>compilation.

>
>
> Don't let syntax fool you: C and C++ are two different languages. Even
> if two languages use the same vocabulary, idioms may be completly
> different.
>
> "Porting" a C program to C++ is an easy task if you only want to
> compile it (well written C code compiles on a C++ compiler, unless C++
> keywords are used).


Not always, there a quite a few C idioms that won't compile as C++, a
couple of common examples:

Implicit cast from void*.
Assignments of integer types to enums.
Macros that use any of the above

--
Ian Collins.
 
Reply With Quote
 
rockstar
Guest
Posts: n/a
 
      05-18-2006
Yea, I've already encounted the void problem I believe, and have been
googling around to find the solution/workaround/port to get this stuff
to work. It also means I have to read the documentation for libraries
I'm not completely familiar with. Victor, as a rule of thumb, I always
google before asking questions, but I've already gotten some good
feedback to the whole process

Paul
http://www.eventuallyanyway.com

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      05-18-2006
rockstar wrote:
> Yea, I've already encounted the void problem I believe, and have been
> googling around to find the solution/workaround/port to get this stuff
> to work. It also means I have to read the documentation for libraries
> I'm not completely familiar with. Victor, as a rule of thumb, I always
> google before asking questions, but I've already gotten some good
> feedback to the whole process
>

Have a look at <http://cfaj.freeshell.org/google/> for some good advice
on posting followups.

--
Ian Collins.
 
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
Porting a WebLink application on Windows 2000 Oriane ASP .Net 0 07-06-2004 12:52 PM
Porting over an ASP.NET application Bijoy Naick ASP .Net 6 05-10-2004 12:46 PM
Porting Code from one machine to another DevBoy ASP .Net 0 05-06-2004 01:14 PM
Advice for Porting existing VB.NET App to ASP.Net Web Application Nate ASP .Net 2 02-18-2004 01:18 AM
HELP - Porting to .NET path? Overworked ASP .Net 2 01-23-2004 10:15 PM



Advertisments