Author Topic: C and C++ question  (Read 2891 times)

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
C and C++ question
« on: 2012-Apr-13 »
Am probably shooting myself in the foot with this question but here goes.

As a lot of you know there are a lot of code snippets and algorithms on the net in C or C++, some of which are well documented and others just the code. With regards to the core features of the 2 languages like loops, decision making etc is there much difference?.

Basically I just want to learn enough to get a rough idea of what's going on in the code so I can implement the algorithm in GLB. Would learning a small bit of C be best or just skip to C++?.

It is not a major thing for me but I sometimes see an effect or an example with some sample code but little or no description on how they done it. Also it would help me when I get a bit more adventurous and start playing with inline code ;D

Lee

Sent from my GT-I5700 using Tapatalk 2
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline hardyx

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 505
    • View Profile
Re: C and C++ question
« Reply #1 on: 2012-Apr-14 »
We can say that C++ is a superset of C. That is, C is the base language for both.

I recommend you first to learn C for two reasons: first because is the base and many libraries was written in C, and second C++ has concepts very complex for a beginner. When you learn C good, you can continue with C++ if you like (if you need).

Moreover, C is the base language of Objetive-C too.

Here you are an easy C tutorial:
http://www.cprogramming.com/tutorial/c-tutorial.html
« Last Edit: 2012-Apr-14 by hardyx »

Offline TI-994A

  • Community Developer
  • Mr. Polyvector
  • ******
  • Posts: 112
  • You can do it in BASIC!
    • View Profile
Re: C and C++ question
« Reply #2 on: 2012-Apr-14 »
With regards to the core features of the 2 languages like loops, decision making etc is there much difference?.

Would learning a small bit of C be best or just skip to C++?
Hello again, Lee.

Simply put, C is C++, but not vice versa. Except for some deprecated ones, most C commands and functions will still work with C++, and even VC# and Objective-C with little or no change to the syntax. These new languages are built on the C command set, but like any new language, the feature set has expanded, and these expansions are not backward compatible. The main differences stem from the program structures and dependencies.

The C programming structure is strictly procedural, while the others can implement both the procedural as well as the object oriented models. However, to take advantage of the rich features of their respective compilers, OO is a must. Here, while pure C++ may be fine for developing apps on any platform, it falls short when it comes to utilising certain OS-specific frameworks. On windows, you'll need a compiler that can utilise CLI, for example VC++ or VC#, and on OSX, you'll need one that can utilise Cocoa, for example Objective-C or Objective-C++.

So, to answer your question about the core features like assignments, loops and logic, they are all basically the same, and it really doesn't make a difference if you start out with C or C++, because syntax-wise they're similar, and feature-wise they're progressive. But do bear in mind that this only holds true with generic C/C++, and not with the other iterations, like VC# and Objective-C; the syntax differences can be progressively different.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!

Offline Ruidesco

  • Mr. Polyvector
  • ***
  • Posts: 236
    • View Profile
Re: C and C++ question
« Reply #3 on: 2012-Apr-14 »
Ideally you could just drop the code into an INLINE and make it work with minimal changes, ie. changing variable types to match the ones used in GLBasic.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2793
    • View Profile
Re: C and C++ question
« Reply #4 on: 2012-Apr-14 »
C first, then C++

Try this little tutorial... http://computer.howstuffworks.com/c21.htm/printable
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: C and C++ question
« Reply #5 on: 2012-Apr-14 »
Thank you all for your answers, very much appreciated.

I could have asked the same question on different forums but I know some of you here have previous experience with both languages so your opinions would have been more unbiased so to speak. There is and probably always will be a C vs C++ war with each camp protecting there language of choice so finding a neutral(ish) forum to ask that question was not so easy to find hence why I asked here.

@bigsofty & hardyx
Thanks for the links, I will surely be checking them out thanks  :D

@Ruidesco
Hopefully that will work with some of the short self contained snippets I have collected over the years, others I need to separate the routines from the complete code example & work out if any of it has been included in etc. Also how inline interacts with passing variables & such like will need to be learnt.

@TI-994a
Most, if not all the code I have collected are C/C++ examples & oddly enough most are C & not C++  :D. Thanks for the explanation about the differences, like I said it is mainly for working out & converting algorithms. Who knows, I might find learning either will be straight forward or a nightmare, for example I once played around with Fortran to help a mate with his studies & it just would not click into place, yet when I played around with Pascal nearly all just slotted into place perfectly.


Lee

"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline 8bitBoss

  • Mc. Print
  • *
  • Posts: 15
  • May the force be with you
    • View Profile
    • http://astutekitsune.tumblr.com
Re: C and C++ question
« Reply #6 on: 2012-Apr-25 »
I would recommend to NOT learn C first. The main difference between C and C++ are classes (object oriented programming) and if you learn C in order to understand C++ than you will always fall back to C code where it's possible. Been there, done that.

I would recommend you learn the concepts of OOP first. My advice would be to download Python and give it a go. The syntax will most likely never get into your way which means you can 100% concentrate on the aspects of OOP. Then, start with C++ properly. Use classes and namespaces from the beginning followed by templates and the STL. C is good for many things. Learning C++ is not one of them imho.
i7 2700k
16GB DDR3 RAM
GeForce GTX 560 Ti
Windows 7 Ultimate 64Bit

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: C and C++ question
« Reply #7 on: 2012-Apr-25 »
I would recommend to NOT learn C first. The main difference between C and C++ are classes (object oriented programming) and if you learn C in order to understand C++ than you will always fall back to C code where it's possible. Been there, done that.

I would recommend you learn the concepts of OOP first. My advice would be to download Python and give it a go. The syntax will most likely never get into your way which means you can 100% concentrate on the aspects of OOP. Then, start with C++ properly. Use classes and namespaces from the beginning followed by templates and the STL. C is good for many things. Learning C++ is not one of them imho.

Thanks for your input, very much appreciated  =D

I have already started my crash course on C as I have more C code snippets & examples than I do C++ ones, of course as time goes on & I start acquiring more C++ code then a rethink or change of strategy may be required.

Like I said it is mainly to convert algorithms & such where documentation is either sparse or non-existent, could be anything from a graphic effect to a routine that parses a file format (a bit like my Amiga Font converter). So it is mainly getting an understanding of how and/or why it was done that way. Sure some of the examples I have could probably be just slotted inline & I just pass the parameters to it, however from a personal point of view that is defeating my goal of learning how it works. At the other end of the scale it may be a case that the converted code may not be possible in GLB or suffer from a major performance hit & in-lining it is the only way. 

The thing that worries me about OOP is not so much learning it but (thinking of a best way to describe this) implementing such code in GLB which is not an OOP language. From various articles I have read regarding OOP I can see the benefits that it provides but using it in GLB I think would be my biggest stumbling block.

In essence GLB does nearly all that I want to do & I cannot see myself writing a complete game/tool etc in C or C++ for the foreseeable future otherwise I would have starting learning them years ago, that does not mean that I might not use one or the other for functions or routines that would otherwise wise be difficult or impossible in GLB.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)