Difference Between C, C++, C# and Objective-C

Pages: 12
Hi!
I just wanted to ask the difference between C, C++, C# and Objective-C. Currently I am learning C++ but for Windows apps I need C and for Mac apps I need Objective-C.
Thanks

Shahmeer
C++ is like C on steroids but is also higher-level.

Take away classes
Take away declaring int in your for loop
Take away iostream, strings, vectors, etc

THen you've got C.

C# is just a higher-level language. More stuff is pre-made for you, so you don't have to go in as deeply.

I don't know much about objective C.
Last edited on
for Windows apps I need C and for Mac apps I need Objective-C
Actually, C++ has been the de facto default language for native Windows development for quite a while.
I don't know what developing for MacOS was like in the pre-10.0 days, but nowadays you can develop for it in pretty much any language. It is true that Objective-C is preferred, though.

[C++] is also lower-level [than C]
No. Just... no.

Take away classes
Take away declaring int in your for loop
Take away iostream, strings, vectors, etc

THen you've got C.
You're forgetting:
* Templates
* Strong typing
* References
* RAII
* Lambdas
* Type inference
* Built-in concurrency
So for Windows development, I am fine with C++? I mean Win32 apps. But in Mac OS X Xcode, I can't find GUI creation in C++.
Regardless of whether the IDE lets you, you can still write GUIs for MacOS using GUI toolkits, such as Qt or wxWidgets. The only downside is that your program will be larger, but on the upside, you'll be able to use a single codebase for both operating systems.
C is a subset of C++. In other words: C++ was made 100% compatible with C code.

Yes, you will be OK using C++ for Windows programming. But you are correct if you are thinking about the Windows API: This API is C, not C++.

I also don't know about Objective-C.
C is also a subset of Objective-C.
Objective-C is a fair punt away from the other two, despite being a superset of C.

Syntactically, it's pretty different. It doesn't follow the dot-notation convention, it uses slightly different keywords and the likes of method calling are quite far from the C/C++ ways.

Conceptually, it's sort of the same. I feel it shares a few more similarities with Java, though, especially in memory management.

I wouldn't bother with Obj-C too much unless you want to develop Cocoa Mac applications or iOS apps.
I code in Obj-C in my day job (which has nothing to do with any Apple devices, and does not use Cocoa). It's a different approach to adding objects to C, adopting the smalltalk model. If what you want is just C with proper objects, it's a lightweight and elegant way of doing it.
I'd argue that there's a slight learning curve in terms a syntax if you're going from C to Obj-C as oppose to C to C++.
Objective C is C with Smalltalk objects bolted on the side.

C++ is C extended with Classes, Templates and Exceptions.
As far as Windows development goes you'll have to write some of your own wrappers and classes but C++ is great (I would even go so far as say ideal) for user mode applications.

The more I read though the more I am leaning toward agreeing with Linus Torvalds, you'd have to be insane to write kernel mode software of any kind in C++, this should only be written in C and the same is probably true for high level logic controllers. Now don't get me wrong, when he says that C++ programmers are inferior and that the Object model is flawed that's just him being an imperialist ass because the old dog doesn't want to learn a new trick and keep up with the times. It comes down to memory management, with the amount of nit-picking you have to do with C++ in kernel mode (always remember to do this, never do that) you've already neutered C++ and you might as well use C.
closed account (3TXyhbRD)
Objective-C and C++ came out almost at the same time. Mac devs preferred Objective-C and made a ton of things for it (you can program apps for any i* thingy with Objective-C). Others wanted to code in C++ and not Objective-C therefore they developed frameworks for C++ (Qt for example).

When OOP came in trend, C programmers wanted to program in that paradigm with a language similar to C and Obj-C and C++ came out as offers to that request.

C# is a Microsoft owned language specially developed for the .NET Framework. It is similar to C.

If you want to program for Microsoft Windows you definitely have to dig into .NET and learn C#. If you want to use a C++-like language to program in .NET look into C++/CLI.

A big difference between C++ and C# or C++/CLI or Obj-C is memory management. Obj-C comes in with some options about dynamic allocation and when dynamic variables are destroyed (which is cool). C# and other CLI languages are imposed by .NET to destroy a dynamic variable when it is not referred anymore (no options). C++ has the C approach, you allocate a dynamic variable? You free that memory! I like the C approach because it optimizes the program (no extra operations are done when you copy a reference), ofc with today's PCs that hardly even matters.
LilJoe said:
If you want to program for Microsoft Windows you definitely have to dig into .NET and learn C#.


This is a common misconception, although Google searching certain things will bring you to MSDN articles on how to do those operations in CLi, .Net or whatever I assure you that it is possible to do all of it in C\C++ as well. You may not WANT to after you see how much work is involved but that's a matter of motivation, not ability.
Last edited on
Objective-C and C++ came out almost at the same time. Mac devs preferred Objective-C and made a ton of things for it (you can program apps for any i* thingy with Objective-C). Others wanted to code in C++ and not Objective-C therefore they developed frameworks for C++ (Qt for example).
While it is true that Objective-C and C++ came out in the same era, Objective-C made it's way into the Mac with OS X and not before. NextStep was implemented in Objective-C, and so it's the native language of the OS X GUI.

When OOP came in trend, C programmers wanted to program in that paradigm with a language similar to C and Obj-C and C++ came out as offers to that request.
C Programmers resisted C++ and only started using it at Bell Labs when it was shown that C++ could generate code as efficient as that generated by C.

C# is a Microsoft owned language specially developed for the .NET Framework. It is similar to C.
C# is similar to Java, not C.

A big difference between C++ and C# or C++/CLI or Obj-C is memory management.
You're pretty much coerced by the environment as far as language goes, you often have little choice. Don't let your personal prejudice get in the way. The difference is the way objects are implemented and used, not memory management.
Last edited on
closed account (3TXyhbRD)
@Computergeek01:
I know I can do anything that .NET offers in C/C++ and other languages using other frameworks. .NET gives a handful of predefined things (open file dialog for example, or any file dialog, even a printer preview and a lot of things that you find in the Windows apps such as Word, Excel etc.). .NET makes things simpler for the programmer but restrains him to a platform (well Mono gives some portability). If you program apps for Windows I don't see the point in looking into other frameworks that take away coding time, .NET is just made for that.

Even with motivation you won't be able to take your time to code sometimes. When you're working against time you'll need the fastest route and that, in some conditions, means .NET. I'm not saying .NET is Godlike but it is an easy alternative for Windows dev.

@kbw:
Isn't an OOP language that generates code as efficient as C is what Stroustrup had in mind when he designed C++?

C# is influenced by C++, Java, Pascal and Modula-3. You may say it's more similar to Java than C, but that doesn't mean C# isn't similar to C (C# has struct, Java doesn't, Pascal doesn't, Modula-3 doesn't.).

I pick the language after what I need to do or want to do. I just pointed a difference between the 4 languages and not said I'll always go for C++ because I can mange memory however I like. The syntax is expected to be different from one language to another.
Another difference are unions, only found in C/C++. Obj-C and C# don't have them. Another difference is that Obj-C is OOP while C isn't, it's just structured. C++ and C# are multi paradigm.
Isn't an OOP language that generates code as efficient as C is what Stroustrup had in mind when he designed C++?
It had to be proved to experienced C developers that C++ was efficient. These guys didn't just move to C++, all their obstacles to using it had to be addressed--including adding protected data to classes, which turned out to be unnecessary. It also meant constraining some object behaviour to achieve this efficiency and static type checking.

Another difference are unions, only found in C/C++. Obj-C and C# don't have them. Another difference is that Obj-C is OOP while C isn't, it's just structured. C++ and C# are multi paradigm.
Objective-C is literally C with Smalltalk Objects bolted on the side. If you don't use objects, you're left with ISO-C. So Objective-C does have everything C has including unions.
It is possible to glue Objective C and C++ at the C level, so you can do all your heavy work in C++ and still have Objective C access to Cocoa. It's definitely a joining of two distinct languages, but I was using it a few years ago and found it quite pleasant.

Also don't feel C# is restricted to Windows. I'm using Mono at the moment for a bit of simple development we need, and being able to compile on my Mac, and copy the executable to a Linux machine and just have it just run is pretty awesome.
Also don't feel C# is restricted to Windows. I'm using Mono at the moment ...
That's interesting. Can I assume that Mono is stable? What .Net version are you using?
.Net 2.0, we've not had reason to upgrade so far. The compiler, gmcs, has offered support for 4.0 for a while now, don't know how good it is though.

For stability, depends on your application. I think mono itself is fine, but I'm not 100% on the framework. I'd definitely be a bit cautious using the less common classes, but I think as long as you stick to the parts of the framework that have been well used/tested you'll be fine.

We migrated some soap web services (low traffic volume though) to mono in May 2011 which run with xsp2 behind an apache proxy and we've never had any issues related to mono.

I've only just started the dev of the app I'm prototyping now, but I'm happy with everything so far.
Pages: 12