C vs C++ vs Objective-C vs etc

This topic was published by and viewed 2190 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author
    Posts
  • DevynCJohnson
    DevynCJohnson
    Keymaster
    • Topics - 444
    • @devyncjohnson

    Many computer users may be confused about the differences between C, C++, C#, Objective-C, and others. Thankfully, the differences are easy to understand.
    To begin, C is a general-purpose low-level imperative procedural programming language. C source code is compiled and does not object-oriented. Libraries are "imported" using code like #include <stdio.h> or #include "local_lib.h". Headers use the "*.h" file-extension while the primary source code uses "*.c".
    Many dialects of C are available such as Cyclone, Unified Parallel C, Split-C, Cilk, and C*. The differences between programming dialects is analogous to the differences between dialects of spoken languages (such as American-English and British-English).
    The various C standards (versions) include ANSI C (ISO C), C89, C90, C99, C11, Embedded C, and MISRA C. These standards are different versions of C, just as there is Old-English (Anglo-Saxon), Middle English, Early Modern English, and Modern English (New English). Some versions of C do not support certain dialects.
    C++ (isocpp.org) is C with additional features, like object-orientation, additional keywords, and the Standard Template Library (STL). C++ also uses a different method for including headers; the file-extension is dropped and "c" is added to the beginning of names of standard-C libraries. For instance, #include <stdio.h> would be written as

    #include <cstdio>[/cpp]. File-extensions for C++ code include "*.cc", "*.cpp", "*.cxx", "*.C", and "*.c++"; header file-extensions include "*.h", "*.hh", "*.hpp", "*.hxx",  and "*.h++". Most (or all) C code will compile successfully using a C++ compiler. C++ supports all features used in C. See <a href="http://www.cs.fsu.edu/~myers/c++/notes/cdiff.html" rel="nofollow">http://www.cs.fsu.edu/~myers/c++/notes/cdiff.html</a> for more information.
    
    <strong>Objective-C</strong> (<a href="https://developer.apple.com/library/mac/navigation/" rel="nofollow">developer.apple.com/library/mac/navigation</a>) is C with the addition of object-oriented programming and Smalltalk-style messaging ([c][obj method:argument];
    ). Also, Objective-C is a strict superset of C and a thin layer on top of C. Header files use the "*.h" file-extension, and primary source code files use the extension "*.m". Objective-C also adds #import which is like #include without the need for include-guards.
    Objective-C++ is C++ with the addition of object-oriented programming and Smalltalk-style messaging ([obj method:argument]; is like
    obj->method(argument);[/cpp]). Header files use the "*.h" file-extension, and primary source code files use the extensions "*.mm" and "*.C".
    
    According to Wikipedia, these differences are also present.
    <blockquote>
    <ul>
     	<li>A C++ class cannot derive from an Objective-C class and vice versa</li>
     	<li>C++ namespaces cannot be declared inside an Objective-C declaration</li>
     	<li>Objective-C declarations may appear only in global scope, not inside a C++ namespace</li>
     	<li>Objective-C classes cannot have instance variables of C++ classes that do not have a default constructor or that have one or more virtual methods, but pointers to C++ objects can be used as instance variables without restriction (allocate them with new in the -init method).</li>
     	<li>C++ "by value" semantics cannot be applied to Objective-C objects, which are only accessible through pointers.</li>
     	<li>An Objective-C declaration cannot be within a C++ template declaration and vice versa. However, Objective-C types, (e.g., Classname *) can be used as C++ template parameters.</li>
     	<li>Objective-C and C++ exception handling is distinct; the handlers of each cannot handle exceptions of the other type. This is mitigated in recent runtimes as Objective-C exceptions are either replaced by C++ exceptions completely (Apple runtime), or partly when Objective-C++ library is linked (GNUstep libobjc2).</li>
     	<li>Care must be taken since the destructor calling conventions of Objective-C and C++’s exception run-time models do not match (i.e., a C++ destructor will not be called when an Objective-C exception exits the C++ object’s scope). The new 64-bit runtime resolves this by introducing interoperability with C++ exceptions in this sense.</li>
     	<li>Objective-C blocks and C++11 lambdas are distinct entities, however a block is transparently generated on Mac OS X when passing a lambda where a block is expected.</li>
    </ul>
    </blockquote>
    <strong>FUN FACT:</strong> At the time of writing this, only GNU-GCC and Clang support Objective-C and Objective-C++.
    
    <strong>C--</strong> or "<strong>C Minus</strong>" (<a href="http://www.cs.tufts.edu/~nr/c--/index.html" rel="nofollow">http://www.cs.tufts.edu/~nr/c--/index.html</a>) is a imperative language that is like C, but without many features (hence "C<strong>--</strong>"). C-- is sometimes called a "portable assembly language".
    
    <strong>C#</strong>, <strong>C</strong><span class="Unicode">♯</span>, or <strong>C-Sharp</strong> is a strongly typed, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming language. C# is like C++, but with many additions and a Common Language Infrastructure (CLI). C# code uses the "*.cs" file-extension. See <a href="https://en.wikipedia.org/wiki/C_Sharp_syntax" rel="nofollow">https://en.wikipedia.org/wiki/C_Sharp_syntax</a> for more information on C#.
    
    <strong>XC</strong> is a concurrent, parallel, imperative programming language intended for real-time embedded parallel processors. This C-language is primarily intended for the XMOS XCore processor (a 32-bit RISC microprocessor). The source-code's file-extension is "*.xc". Code written like [c]par { f(); g(); }
    would be executed in parallel. "Channels" can be used for communication using the send (<:) and receive (:>) operators. XC was influenced by the occam programming language.
    or C-Omega is an event-driven language that is an extension of C#. Cω also offers concurrency and datastore data-types (such as XML documents and databases). Polyphonic C# is an extension of C# with concurrency. However, Polyphonic C# was merged with Cω. See http://research.microsoft.com/en-us/um/cambridge/projects/comega/ for more information. To use Cω in C#, import the Cω library using the code using Microsoft.Comega;. Cω is supported by many C# compilers.
    μC++ or UC++ is an extension of C++ with concurrency, coroutines, and additional features. This language has additional reserved keywords such as _Resume and _Coroutine. See http://plg.uwaterloo.ca/~usystem/uC++.html for more information.
    C* is an object-oriented and data-parallel form of C designed by the company Thinking Machines.
    Dataparallel-C is a form of C with parellel-extensions designed by Hatcher and Quinn of the University of New Hampshire.
    Some languages that are similar to C and/or C++ include GoLang, Limbo, Alef, D, and Vala. Vala can output C code.

    Further Reading

Viewing 1 post (of 1 total)