View Full Version : C, C+, C++ and C#

08-19-2006, 01:48 AM
I have heard that C is becoming older and that C# is becoming more relant.
I also heard that each step forward in C is backwards compatable.

First question - Which is the better language to learn looking at it from a view point of whats to come.

Second question - is it backwards compatable?

Chris Savage
08-19-2006, 01:56 AM
This thread is being moved from the·Robotics Forum to the·Sandbox Forum.

Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

John R.
08-19-2006, 02:35 AM
Well, that depends if you're working in a Microsoft centric environment or not.

C# (C Sharp) is basically a "C like syntax" wrapped over Visual Basic Functions. There is pretty much a one to one mapping between VB Functions and C# functions. (It may be exactly 1:1, but I'm leaving a fudge factor in place.)

Outside of a Microsoft environment, C# is virtually non-existant.

I think you may have the right idea, but possibly wrong syntax in saying "C is backwards compatable". GENERALLY, C code from an older version of a C Compiler will move forward (or a C complier will work "backward" with code). New C code is less likely to work with an older complier, assuming you take advantage of new features in the new compiler.

It might (depending on the specific environment) be more appropriate to say that it isn't the "C Language" that's getting upgraded, but the interface, and any libraries the vendor has written.

When dealing with microprocessor environments (like the STAMP, SX, or Propeller) the compiler is kind of working as a "translator" and "converting" your C Code into either assembly code, or some type of token set for further processing.

In any of the cases with "plain old C", if you code doesn't use macros specific to the development environment, or special libaries that are subject to evolution and change, it should be fairly portable, both forward and backward, and even from different environments (PC to Unix to Microprocessors). Of course this totally falls apart if you take a C program designed to put a bunch of graphics on a PC screen, and try and use the same code to drive graphics on a totally different system (for example from a PC to a MAC or Linux box). This isn't really the "C" Code, but the libraries used.

C++ is object orientated C, and is really a system unto itself. Most C++ code tends to be machine or environment specific, not becuase of the nature of C++, but due to the "standard (read Vendor Specific) libraries" included with the various C++ Compilers.

If it were only that simple (as stated above) life would be good, but at least I hope I've given you some answers that make sense.

John R.

8 + 8 = 10

Kaos Kidd
08-19-2006, 03:09 AM
Well put!


Propeller + Hardware - extra bits for the bit bucket =· 1 Coffeeless KaosKidd


Mike Green
08-19-2006, 03:25 AM
Like all such questions, it depends on what you want to do. C is still very very useful, particularly when you're working with limited resources as in microcontrollers or hand-held computers (PDAs). There is a nice C compiler that runs on the Palm PDA, is fast, and produces native (68000) code. There are free C compilers that also run on embedded DOS computers with minimal resources. C++ like C is a standard language. You can find compilers that run on any desktop or laptop computer whether it's using Linux, Windows (of any version past Windows 98), or the Mac OS and produce excellent optimized native or cross compiled code for a variety of processors. C# is essentially a Microsoft proprietary extended C++. It's not as available widely as the supurb free open source compiler system originally developed for Linux and now running on all kinds of processors and OSs and it accepts C, C++, Pascal and others.

Unless you have a special reason for using C#, I would stick to a standard language like C or C++. If you're going to be programming for microcontroller-based embedded systems, I'd stick to C. If you're mostly working with desktop and laptop systems or resource-rich embedded systems, go for C++.

My own particular bias is towards Pascal and its derivatives including Delphi. It's a language where you can express low-level concepts easily yet it enforces type checking which helps a lot in terms of avoiding errors. There's an excellent native Pascal compiler for the Palm PDA that compiles into either 68000 (old - emulated) or THUMB (new - really native) instructions.

If you want to do really AI-ish stuff, I would stick to LISP, particularly the Scheme dialect. Scheme is very powerful, yet has some features (like special handling of tail recursion) that allow efficient interpreters and compilers. There's an interpreter for the Palm OS that's quite good although old and not maintained much and it's now open source.

John R.
08-19-2006, 04:02 AM
Mike Green said...


·C# is essentially a Microsoft proprietary extended C++.


See above, Not to quible, but I believe it is more closely aligned with VB than C++.·

I'll second the rest of the comments, but I'm not as fond of Pascal/Delphi (personal preference, nothing wrong with either).

I like LISP, It's fun.· I learned it as part of developing in older AutoCAD environments and did a few other projects with it.· Kind of out there on the fringes.

In direct answer to #1 of the original poster, and expanding on Mike's post:

It really does depend on what you are targeting, both from a perspective of application, and from the standpoint of what "platform" or "environment" you're going to be working in.

C or C++ and various flavors thereof (Visual C++, gnu C/C++, etc.) are possibly the most "universal" of languages at this point in time.· However, you can't (easily) program a web page in C/C++, or other devices (like the Propeller).

On the other hand, if you're thinking about a career in programming, you'll probably need to do some web based programming, and then you'll be needing PHP, Java and/or one of the various flavors of MS Scripting and/or .NET.

You'll see "veteran" progammers with a seemingly unending list of languages they've worked in.· The real thing to understand is that if you learn and develop good programming habbits and practices, picking up another language isn't that hard once you've learned the first couple.·

My personal suggestion: Pick a language to work on a project that you will enjoy.· If it's something with a STAMP, use PBasic.· If it's in Windows, use your choice of language.· Get "proficient" with that language.· Once you are comfortable, try a different language, and go from there.

John R.

8 + 8 = 10

Post Edited (John R.) : 8/18/2006 9:16:54 PM GMT

Mike Green
08-19-2006, 04:37 AM
Ditto John's comments. It's like learning "foreign" languages. There are a lot of similarities, particularly among the Romance languages and among the Germanic languages. You can learn a lot from the differences between them and the concepts that some have and others do not (and vice versa). Tonal languages like Chinese require whole new skills from someone not raised on them. People often have programming "accents" that say a lot about what they learned first or most recently. It's also very different being a "tourist" vs. "living in a place". Programming languages tend to color how you think about a problem and knowing several helps you keep free of that.

08-20-2006, 08:45 AM
>> try and use the same code to drive graphics on a totally different system (for example from a PC to a MAC or Linux box).

Unless you are using a cross-platform library, like Qt or GLUT/OpenGL...

08-21-2006, 09:27 PM
What I am looking at is a few different things.

I want to do robotics. The books on PBasic are good and I have a few BS2's that are handy, but the concept of getting a propeller chip has come to mind which would mean learning SPIN. I want to get into AI. It is fascinating. I want to explore the possablitilites of the new Microsoft Robotics Studio which uses C# I want to write a game - there are two I have in mind - and haven't picked a language. There are books on Game AI that come to mind but doesn't mean thats the way to go. I want to build a few data bases. I work with VBA and EXTRA Basic all day and even though VBA is useful it limits what I can do to mainly microsoft. VBA is starting to feel stiffled and the need to stretch beyond is becoming more and more apparent.

The thought of learning LISP or PROLOG is something I have toyed with for awhile·- can LISP be used with the games I want to build? IF so whats a good resource for starting?

Getting back to the main question - given what is being considered what would be the recommendation to learn? C? C++? C#? or maybe something else?

John R.
08-21-2006, 10:02 PM
If you know VBA, you all but know C#. This (C#) would be a good "transition" step. I believe You can get the "lite" development ket from MS for free. It will also give you a nice transitional way to learn the "syntax" of C, without needing to actually learn the C languange per se. Then you could have a step 2 transition from C# to C or C++ or "Visual C", and be able to learn the language, having already learned the syntax.

Given your list of "want to do", this probably makes the most sense.

The ability to do games in LISP will depend on what user interface you want, and what LISP toolkit you use. In the "early" role playing games where everything was a text interface ("Game: You are in a room, there are three exits. User: Walk through center exit...") some of these were done with LISP. I don't know if you'll find a LISP compiler that will support graphics, etc. One alternative migh be to use someting like VB/C# or Visual C and write the graphics and user interface, and then call other programs or libraries written in LISP.

John R.

8 + 8 = 10

Post Edited (John R.) : 8/21/2006 3:53:04 PM GMT

Mike Green
08-21-2006, 10:15 PM
Look at <www.plt-scheme.org> for a free, excellent implementation of Scheme (LISP) with books available, a GUI library, and many other features. It runs under Windows, Mac OS, and Linux and the Windows version has a COM library so you can build Active-X and COM-based interactive programs. It's intended for a teaching environment, so there's lots of examples and exercises.

Kevin Wood
08-21-2006, 11:15 PM
Lisp can be used to build games, but you'll find more resources for other languages. When people say Lisp, they mostly are referring to Common Lisp, but there are other dialects. If you want to give it a try, I suggest Scheme, as Mike Green did. It is a simpler dialect than Common Lisp, but very powerful.

C, C++, & C# are three very different languages, and are all used a bit differently. The 2 closest are C/C++, since C++ was built on top of C. C# is really a clone of Java, with some differences.

As for which one to learn, I suggest you start with plain old C. It's a much smaller language than the others, so it will be easier to learn & put to use quickly. You will be able to take most of what you learn to C++, and some of it to C#.

As for how to learn, I suggest you start with a product called Ch, which is a C/C++ interpreter. Setting up a C compiler can be a hassle, so rather than trying to figure out makefiles & compiler options, Ch isolates you from the process. Once you get a bit of experience, you can use a compiler if you want. Even if you use a compiler from the outset, Ch is very good for prototyping and trying things out, especially with the related ChSciTE text editor, since you don't need to set up any tools.

For Scheme, take a look at: www.plt-scheme.org (http://www.plt-scheme.org)

For Ch, take a look at: www.softintegration.com (http://www.softintegration.com)

08-22-2006, 08:28 AM
If by game, you mean something like Doom or Halo, then you will need to learn C and C++, and OpenGL w/ GLSL; as well as some platform specifics depending on where you intend to develop/deploy...

>> Setting up a C compiler can be a hassle,

Or, not... depending on which compiler you choose (and which platform you are on). On OS X, the developer tools install like any other app; any standard install of Linux will include gcc already; and any of the Turbo-series DOS compilers is an easy setup...

On OS X, Xcode can be downloaded for free from:

Turbo C++ 1.01 for DOS can be downloaded here for free:

Not yet released, but available soon:

For professional development, you will probbably want an optimising compiler that targets a modern platform (such as gcc under OS X or Linux; or any of the Borland products for Windows, or MS VC++).

Microcontrollers require a C compiler specific to that MCU; AVR, PIC, 8051, and (soon) the SX all have compilers that I am aware of. C/C++ tools are available for a number of other embedded processors as well (PPC, ColdFire, XScale, and DragonBall CPUs all come to mind). However, the Basic Stamp (and clones), Propeller, and a few others, require a language specific to the MCU (usually because of special hardware features - like, for example, the 8-core nature of the Propeller).

08-23-2006, 02:53 AM
Thanks to all.

I found a book on C and one on C# and it sounds like they are good places to start. The SDK download uses C# so that will become a used language and C seems to be pretty common.