Forum Archive

Go Back   3D Realms Forums > General Topics > Programming Forum
Blogs FAQ Community Calendar

Notices

 
 
Thread Tools
Old 08-21-2010, 07:22 PM   #1
Stroggos
Smirk C vs. C++
I'm having somewhat of a crisis at the moment in my own little programming projects. I'm a C programmer mainly, but I have dabbled in some C++ when I feels its needed, but I'm trying to figure out what are the pros and cons of porting all my code to C++. Could someone explain this?
Stroggos is offline  
Old 08-21-2010, 07:26 PM   #2
ZuljinRaynor

ZuljinRaynor's Avatar
Re: C vs. C++
C++ is much more strict than C++, but it is just as it says, C better better. It's more powerful.
__________________
My vision is augmented.
ZuljinRaynor is offline  
Old 08-22-2010, 02:43 AM   #3
TerminX

TerminX's Avatar
Re: C vs. C++
All of the added stuff in C++ has more overhead than just coding in straight C.
TerminX is offline  
Old 08-22-2010, 08:39 AM   #4
Jiminator

Jiminator's Avatar
Re: C vs. C++
I believe you can enforce strictness with C.

The main advantage is maintainability, assuming by "convert" you turn everything into black box type objects.
__________________
big badass nasty weapons here....
Jiminator is offline  
Old 08-25-2010, 07:23 AM   #5
Crosma

Crosma's Avatar
Exclamation Re: C vs. C++
The main argument from my point of view is that C++ only offers abstraction of things that you can already do in C, without being any simpler to code or understand. Creating new objects is like using malloc() and deleting them is like using free(). Objects are just structs with member functions, but you can achieve the same results by passing struct pointers. Function overloading is somewhat possible in C (see printf()), but I consider it to be bad practice anyway.

Inheritance, abstraction, encapsulation, and polymorphism are kind of cool, but you can achieve similar results by using struct pointers (and I suspect that's all they're doing at a lower level).

C keeps you in the loop. You can see exactly how your data is structured and how and what is being passed where. It's all about keeping the control firmly in the programmer's hands.
__________________
(define love (lambda () (map conquer all)))
Crosma is offline  
Old 08-25-2010, 03:57 PM   #6
8IronBob

8IronBob's Avatar
Re: C vs. C++
C++ is more object-oriented, too, than traditional C, that's the primary difference...and yes, the code structure is slightly different. C++ uses a more streamlined codeset, and uses less code to run a program from that of a comparable C program. There are good tutorials on C++, I suggest logging in to 3D Buzz and go to their C++ section. They make very good video tutorials, or VTM packages on specific topics.
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 08-25-2010, 09:12 PM   #7
Jiminator

Jiminator's Avatar
Re: C vs. C++
um, except that you can make c++ functions to be private to enforce the black box concept. same with classes. you can maintain classes. the problems come in when people add hacks to do special things. then cleaning up the code causes huge problems or unexpected breaks. may not be an issue on small projects. on enterprise scale however things like that can cause massive setbacks. think about things like structs and bit arrays and constants to access them. look at early windows programming. it is a joke.
__________________
big badass nasty weapons here....
Jiminator is offline  
Old 08-26-2010, 06:34 AM   #8
Crosma

Crosma's Avatar
Exclamation Re: C vs. C++
Quote:
Originally Posted by Jiminator View Post
um, except that you can make c++ functions to be private to enforce the black box concept. same with classes.
That's what C-style static variables/functions are for. It's the same feature with the same purpose, for all intents.
__________________
(define love (lambda () (map conquer all)))
Crosma is offline  
Old 08-26-2010, 07:02 AM   #9
TerminX

TerminX's Avatar
Re: C vs. C++
Quote:
Originally Posted by Crosma View Post
The main argument from my point of view is that C++ only offers abstraction of things that you can already do in C, without being any simpler to code or understand. Creating new objects is like using malloc() and deleting them is like using free(). Objects are just structs with member functions, but you can achieve the same results by passing struct pointers. Function overloading is somewhat possible in C (see printf()), but I consider it to be bad practice anyway.

Inheritance, abstraction, encapsulation, and polymorphism are kind of cool, but you can achieve similar results by using struct pointers (and I suspect that's all they're doing at a lower level).

C keeps you in the loop. You can see exactly how your data is structured and how and what is being passed where. It's all about keeping the control firmly in the programmer's hands.
I usually argue with everyone's posts, but this one is good. I've been writing nothing but C for the better part of a decade and you hit the nail on the head as to why I can't bring myself to care about C++. C is about as low level as anyone is going to get without getting into all of the asm stuff that becomes less relevant as the years go by due to the increasingly powerful optimizations going on behind the scenes in C compilers as it is.

Unless the job at hand is somehow made a lot faster or clearer by all of the hand holding of a higher level language, use C!

For what it's worth, some bad-ass programmers who clearly know their shit are also in the C++ hate camp. Linus Torvalds immediately comes to mind. People got on fine for years without C++ and so can you.
TerminX is offline  
Old 08-26-2010, 07:50 AM   #10
Sang

Sang's Avatar
Re: C vs. C++
Where does C# fit into this story exactly? (I'm genuinely wondering)
__________________
traB pu kcip
Sang is offline  
Old 08-26-2010, 09:04 AM   #11
Jiminator

Jiminator's Avatar
Re: C vs. C++
C# is a microsoft joke language. it requires .net framework to run and is not compatible across all platforms.
__________________
big badass nasty weapons here....
Jiminator is offline  
Old 08-26-2010, 02:46 PM   #12
8IronBob

8IronBob's Avatar
Re: C vs. C++
Quote:
Originally Posted by Jiminator View Post
C# is a microsoft joke language. it requires .net framework to run and is not compatible across all platforms.
True, and I believe that XNA requires it, too, and I believe you have to use at least .Net 3.0 to use that. Here I am stuck with VS2005 Standard, and just hoping to scrape enough to upgrade to VS2010 Professional. I believe Newegg did lower the price to $480 for the upgrade edition, which is nice, but...I even wonder if my edition of VS2005 is even eligible for that upgrade.
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 08-26-2010, 04:36 PM   #13
alexgk

alexgk's Avatar
Re: C vs. C++
Quote:
Originally Posted by ZuljinRaynor View Post
C++ is much more strict than C++
What?!
-----------------

Personally, most of the time I've programmed guided by the object-oriented paradigm. I don't see how OOP can be a bad thing, when it comes to complexity. On the contrary, it helps you build software easier to design, to document and to maintain. It's also true that it creates an overhead, that's a con, but sometimes, I read code in C, which is dirty as hell, I have no idea what's going on.

Actually, I'd love to learn some C/C++ game programming. The only experience I've had in game programming is with C# and XNA
__________________
Playable demo this year! Confirmed!!
alexgk is offline  
Old 08-27-2010, 05:57 AM   #14
Delta

Delta's Avatar
Re: C vs. C++
Use whatever language you feel more comfortable with.

Personally I don't mind either language. C gives you fairly low-level control over everything and is a relatively simple language to just keep in your head. And C++ has nice bells and whistles like objects, namespaces, polymorphism, convenient vector/list/string/map classes in the standard library, and other things. C++ gives you more conveniences so that you don't have to reinvent the wheel, but on the other hand it doesn't tell you how the wheel was invented in the first place.

One thing I must say though: If you're really experienced in C, it can make you better at C++ should you decide to use it. Because since you know more about what's going on under the hood, it keeps you from making similar mistakes later on.

Also C# has pretty much nothing to do with either language. It shares a similar syntax style and similar name, but is otherwise completely different; different libraries, different idioms, different standards, code is incompatible with C/C++, etc. It's just as separate as Java is from C++.
Delta is offline  
Old 08-27-2010, 04:35 PM   #15
IceColdDuke
Re: C vs. C++
Quote:
Originally Posted by TerminX View Post
I usually argue with everyone's posts, but this one is good. I've been writing nothing but C for the better part of a decade and you hit the nail on the head as to why I can't bring myself to care about C++. C is about as low level as anyone is going to get without getting into all of the asm stuff that becomes less relevant as the years go by due to the increasingly powerful optimizations going on behind the scenes in C compilers as it is.

Unless the job at hand is somehow made a lot faster or clearer by all of the hand holding of a higher level language, use C!

For what it's worth, some bad-ass programmers who clearly know their shit are also in the C++ hate camp. Linus Torvalds immediately comes to mind. People got on fine for years without C++ and so can you.
Well you give yourself way better odds of finding a job if you know C++.
IceColdDuke is offline  
Old 08-27-2010, 05:50 PM   #16
peoplessi

peoplessi's Avatar
Re: C vs. C++
Quote:
Originally Posted by Jiminator View Post
C# is a microsoft joke language. it requires .net framework to run and is not compatible across all platforms.
That's just false C# is actually pretty nice language - the only thing downside is that MS is giving full support for their own platform. mono is pretty advanced, but doesn't (yet) support full features of C#. It's across Mac, Linux and Windows - all the primary platforms. On mobile side there is Windows Phone 7.

Also, I would like to hear why do feel it's a "joke" language? Just saying it's "joke" is not convincing at all.

Quote:
Originally Posted by 8IronBob View Post
True, and I believe that XNA requires it, too, and I believe you have to use at least .Net 3.0 to use that. Here I am stuck with VS2005 Standard, and just hoping to scrape enough to upgrade to VS2010 Professional. I believe Newegg did lower the price to $480 for the upgrade edition, which is nice, but...I even wonder if my edition of VS2005 is even eligible for that upgrade.
Stop posting stuff like this please You can download the Express edition for free, yeah free. Until you really need the features of full-fledged version of VS, there's no need to shell out the money for VS2010. XNA is a nice way of getting knee-deep in the development for multiple platforms.
__________________
Duke Nukem Forever
Who am I to judge?
Last edited by peoplessi; 08-27-2010 at 05:53 PM.
peoplessi is offline  
Old 08-27-2010, 09:01 PM   #17
Jiminator

Jiminator's Avatar
Re: C vs. C++
eh, c# is the microsoft answer to java, with the exception that for full feature you have to use a microsoft platform. I was not impressed when it originally came out. that being said, you appear to be more expert on it, so I'll take your word for it.
__________________
big badass nasty weapons here....
Jiminator is offline  
Old 08-28-2010, 06:02 AM   #18
Crosma

Crosma's Avatar
Exclamation Re: C vs. C++
Quote:
Originally Posted by IceColdDuke View Post
Well you give yourself way better odds of finding a job if you know C++.
Well you give yourself way better odds of finding a job if you know PHP. Shame that PHP is pish.

Yes, I write PHP and C for work. Odd combination, but whatever.

Quote:
Originally Posted by peoplessi View Post
C# is actually pretty nice language
I agree, but it's not significantly different from Java. Except that Java has exceptional cross-platform support. Mono is quite fine, as long as you intentionally develop for it. Otherwise it's unlikely that the program will work correctly.

Also, IBM J9 is the business. Makes Eclipse run like silk.

Quote:
Originally Posted by peoplessi View Post
You can download the Express edition for free, yeah free.
Whoop-dee-doo. All of the tools I use are free anyway.
__________________
(define love (lambda () (map conquer all)))
Crosma is offline  
Old 08-28-2010, 06:56 AM   #19
peoplessi

peoplessi's Avatar
Re: C vs. C++
I mostly do PHP , but some C# too. Very little of C, a bit more of C++. All have their uses and places.
__________________
Duke Nukem Forever
Who am I to judge?
peoplessi is offline  
Old 08-29-2010, 05:52 AM   #20
Sang

Sang's Avatar
Re: C vs. C++
All I've done so far is Java (and assembler) so **** if I know anything about this
__________________
traB pu kcip
Sang is offline  
Old 08-29-2010, 12:10 PM   #21
IceColdDuke
Re: C vs. C++
Quote:
Originally Posted by Crosma View Post
Well you give yourself way better odds of finding a job if you know PHP. Shame that PHP is pish.

Yes, I write PHP and C for work. Odd combination, but whatever.
Not really, I've mixed PHP and C++/Assembly. It works good in look disassembly outputs to insert code in certain locations.

It really depends on what kind of work you want to pursue, but knowing C without knowing C++ I doubt you will find work at least in the US.
IceColdDuke is offline  
Old 08-30-2010, 02:21 PM   #22
8IronBob

8IronBob's Avatar
Re: C vs. C++
Speaking of getting C++ for free, I think Borland had their Turbo C++ program for that, did they not? I thought the last time I visited their website, they did. Believe it or not, when I first did learn C/C++, it was under Borland (since my father worked for an engineering company, he knew friends that used this, which I was introduced to it), and I really liked what TC++ had to offer. They even had proprietary graphics codesets, too, which nobody else had, including VC++ at the time. Ahh, teh memoriez!
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 08-30-2010, 06:39 PM   #23
Jiminator

Jiminator's Avatar
Re: C vs. C++
I used to have a copy of their turbo pascal (before "borland"). which was a pretty awesome and powerful programming language for the time. I think it cost $70. Anything comparable was $500 or more. Heck, I still have a copy of the original microsoft assembler which cost some $250.
__________________
big badass nasty weapons here....
Jiminator is offline  
Old 09-01-2010, 02:36 PM   #24
8IronBob

8IronBob's Avatar
Re: C vs. C++
I see...anyway. To get back to the point of the OP, I'd say that if you're just starting out, it's best to do so by learning vanilla ANSI C first. Do a few test programs with that, and when you're comfortable, and learned everything there is about C, then you move on to C++, then on to C#, which will lead to XNA Game Development and Unity. Just my two bits.
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 09-02-2010, 06:44 AM   #25
Crosma

Crosma's Avatar
Exclamation Re: C vs. C++
Quote:
Originally Posted by 8IronBob View Post
C, then you move on to C++, then on to C#
I don't see any natural transition to C#. It's like it's a particularly C-like language. You might as well just start with C# if that's how you're going to play it.

If I'm writing a C program, I'm usually looking for an optimal performance and memory footprint, which is certainly not what you're going to get from C#. Different tools for different jobs.
__________________
(define love (lambda () (map conquer all)))
Crosma is offline  
Old 09-02-2010, 02:08 PM   #26
8IronBob

8IronBob's Avatar
Re: C vs. C++
Yeah, I know, I also got carried away about Unity there, too...guess I must've been spending too much time around 3D Buzz's website again.
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 09-02-2010, 03:31 PM   #27
peoplessi

peoplessi's Avatar
Re: C vs. C++
8IronBob, I agree with Crosma. There is no logic behind your C, C++ to C# vision. Also, I can't see why one would learn two languages before the language one is really interested in? Just start with what ever pleases you most. There are languages for every job.

Getting grips with new languages is rather fast once you've got the programmers mind-set.
__________________
Duke Nukem Forever
Who am I to judge?
peoplessi is offline  
Old 09-28-2010, 04:33 PM   #28
8IronBob

8IronBob's Avatar
Re: C vs. C++
Yeah, guess you're right. However, a lot of things are going more the way of C# now, and going with the .Net Framework protocol. Seems like Microsoft is really babying that language to death now. Although I do like Visual C++ and Visual Basic, and the like, VC# just seems to be the way to go now. Just like the speedy code development in it.
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 09-28-2010, 07:14 PM   #29
Dopefish7590

Dopefish7590's Avatar
Re: C vs. C++
If you already know C, you could very easily stick with it, IIRC C++ was an addition of the C language with classes so that making large applications was easier.
Also, wasn't C++ a language that compilers used to convert to C before compiling?
Dopefish7590 is offline  
Old 09-28-2010, 08:32 PM   #30
Jiminator

Jiminator's Avatar
Re: C vs. C++
They could. Given any particular platform if you can get standard C to run on it then C++ will work also
__________________
big badass nasty weapons here....
Jiminator is offline  
Old 09-29-2010, 06:23 AM   #31
Crosma

Crosma's Avatar
Exclamation Re: C vs. C++
Quote:
Originally Posted by Dopefish7590 View Post
Also, wasn't C++ a language that compilers used to convert to C before compiling?
Comeau C/C++ translates C++ to C then compiles that (or you can compile with something else). It's also got the most standards compliant C++ support. C++ was explicitly designed to be translated to C, and that's how it was done for a long time, but we generally use true C++ compilers now.

The original C++ "compiler" was called Cfront, and also did the translation thing. It turns out that Cfront was abandoned when exceptions were added to C++, but Comeau will translate a C++ program with exceptions to C.
__________________
(define love (lambda () (map conquer all)))
Last edited by Crosma; 09-29-2010 at 06:29 AM.
Crosma is offline  
Old 10-01-2010, 07:04 AM   #32
8IronBob

8IronBob's Avatar
Re: C vs. C++
Yeah, I think that VC++ 2010 Express seems to be a bit more biased towards C++ than C, from experience. I mean, when you open a project, it automatically loads to .CPP source files, as opposed to letting you choose between .CPP or .C. You'd have to manually do an empty project for doing plain C programs, I'm pretty sure.

Anyway, looks like 3D Buzz has some good tutorials on C++, tho, I really got a lot out of those VTMs. Although I believe their tutorials come from VS 2003 or something. There could be a few changes from those days to VS 2010's.
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 10-01-2010, 10:50 AM   #33
ZuljinRaynor

ZuljinRaynor's Avatar
Re: C vs. C++
Quote:
Originally Posted by 8IronBob View Post
Yeah, I think that VC++ 2010 Express seems to be a bit more biased towards C++ than C, from experience. I mean, when you open a project, it automatically loads to .CPP source files, as opposed to letting you choose between .CPP or .C. You'd have to manually do an empty project for doing plain C programs, I'm pretty sure.
I mean, it's not like the program has C++ in it's name.
__________________
My vision is augmented.
ZuljinRaynor is offline  
Old 10-01-2010, 11:51 AM   #34
Jiminator

Jiminator's Avatar
Re: C vs. C++
for most people there is not any reason you should not be using a c++ compiler. About the only reason you would want to use C is if you had legacy applications that did not compile properly in C++ that nobody wants to spend the time + money to clean up.
__________________
big badass nasty weapons here....
Jiminator is offline  
Old 10-01-2010, 02:40 PM   #35
8IronBob

8IronBob's Avatar
Re: C vs. C++
Well, then in that case, it probably may be best to download MinGW for doing vanilla C.
At least that will allow for more flexibility, since Visual C++ is rather specific to a different flavor of C/C++ over other compilers out there. Borland was another that had their own brand of C/C++ code, etc... Depends on the company's proprietary platform.
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
Old 10-01-2010, 04:28 PM   #36
Dopefish7590

Dopefish7590's Avatar
Re: C vs. C++
Quote:
Originally Posted by 8IronBob View Post
Well, then in that case, it probably may be best to download MinGW for doing vanilla C.
This.
GCC is awesome.
Dopefish7590 is offline  
Old 10-01-2010, 05:43 PM   #37
8IronBob

8IronBob's Avatar
Re: C vs. C++
Well, sure, I can mix it up. On top of that, C++Compiler 5.5's a free one, too, even tho Borland was bought out by some Mexican company (Embarcadero), now I can't get Turbo C# or Turbo C++ free anymore.
__________________
PC Specs (a.k.a. "Galacticus Prime"): http://pcpartpicker.com/p/7Vk7FT
8IronBob is offline  
 

Bookmarks


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

Forum Jump


All times are GMT -6. The time now is 06:41 AM.

Page generated in 0.17793703 seconds (100.00% PHP - 0% MySQL) with 15 queries

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

Website is ©1987-2014 Apogee Software, Ltd.
Ideas and messages posted here become property of Apogee Software Ltd.