Authors Puneet Bhalla Surbhi Gupta
License CC-BY-4.0
ANALYSIS 5(14), August 1, 2013 Discovery ANALYSIS ARTICLE ISSN 2278–5469 EISSN 2278–5450 Comparative study of C, Objective C, C++ programming language Surbhi Gupta, Puneet Bhalla Dept. of Computer science & Engineering, Dronacharya College of Engineering, Gurgaon, India Publication History Received: 14 June 2013 Accepted: 17 July 2013 Published: 1 August 2013 Citation Surbhi Gupta, Puneet Bhalla. Comparative study of C, Objective C, C++ programming language. Discovery, 2013, 5(14), 11-14 Publication License This work is licensed under a Creative Commons Attribution 4.0 International License. General Note Article is recommended to print as color digital version in recycled paper. ABSTRACT “A programming language is an artificial language designed to express computations that can be performed by a machine, particularly a computer”. The initial development of C occurred at AT&T Bell Labs between 1969 and 1973. It was named "C" because its features were derived from an earlier language called "B" was a stripped-down version of the BCPL programming language. This language was created for a specific purpose to design the UNIX operating system. From the beginning, C was intended to be useful--to allow busy programmers to get things done easily and without remembering the register binary values which was a major problem in coding with C language. To overcome problems of Objective-C language new language is derived in 1980’s. With concept of object oriented and some predefined rules or functionalities a language is designed known as C with classes. Later this language gets its originals name i.e., C++. C++ is a language which is semi dependent on machine and which is easy to understand. C++ is different from C in terms of syntaxes, header files, some rules and many more things. The C and C++ programming languages are closely related. C++ grew out of C, as it was designed to be source-and-link compatible with C. However, due to minor semantic differences, most non-trivial C programs will not compile as C++ code without modification—C++ is not a strict superset of C. This research paper concludes withthe influence of one language to another and comparative study of the languages. Keywords: C++, C, UNIX, OBJECTIVE C. 1. INTRODUCTION approved a version of C in 1989 which is known as ANSIC. With few exceptions, every modern C compiler has the ability to adhere to this This paper is about the comparison of the C, Objective C & C++ standard. ANSI C was then approved by the International Standards programming language, the influences of one language on another, and the Organization (ISO) in 1990” (A Brief History of the C Language). There is conditions under which they were created. “C is a programming language something interesting about the name of C. It was named C because its which born at ‘AT & T’s Bell Laboratories’ of USA in 1972. It was written by predecessor was called B which was also developed by Ken Thompson of Bell Dennis Ritchie. This language was created for a specific purpose: to design Labs (A Brief History of the C Language). the UNIX operating system (which is used on many computers). From the The Objective-C language is a simple computer language designed to beginning, C was intended to be useful--to allow busy programmers to get enable sophisticated object-oriented programming. Objective-C is defined as 11 things done” (A Brief History of the C Language). After that, C began to be a small but powerful set of extensions to the standard ANSI C language. Its used by more and more people outside the Bell Laboratories because it is Page additions to C are mostly based on Smalltalk, one of the first object-oriented more efficient than other programming languages at that time. In the late programming languages. Objective-C is designed to give C full object- 70’s, C took the dominant position of programming languages. “The oriented programming capabilities, and to do so in a simple and committee formed by the American National Standards Institute (ANSI) © 2013 Discovery Publication. All Rights Reserved. www.discoveryjournals.com OPEN ACCESS ANALYSIS ARTICLE straightforward way. It is the main programming language used by Apple for 2.2. C++ the OS X and iOS operating systems and their respective APIs, Cocoa and Stroustrup found that Simula had features that were very helpful for large Cocoa Touch. software development, but the language was too slow for practical use, while “C++ was written by BjarneStroustrup at Bell Labs during 1983-1985. BCPL was fast but too low-level to be suitable for large software C++ is an extension of C. Prior to 1983; BjarneStroustrup added features to C development. When Stroustrup started working inAT&T Bell Labs, he had the and formed what he called ‘C with Classes’. He had combined the Simula's problem of analyzing the UNIX kernel with respect to distributed computing. use of classes and object-oriented features with the power and efficiency of Remembering his Ph.D. experience, Stroustrup set out to enhance the C C. The term C++ was first used in 1983.” A Brief History of C++ “C++ was language with Simula-like features. C was chosen because it was general- designed for the UNIX system environment, it represents an enhancement of purpose, fast, portable and widely used. Besides C and Simula, some other the C programming language and enables programmers to improve the languages that inspired him were ALGOL 68, Ada, CLU and ML. In 1983, the quality of code produced, thus making reusable code easier to write” (Online name of the language was changed from C with Classes to C++ (++ being C++ tutorial). the increment operator in C). New features were added including virtual, function name and operator overloading, references, constants, user- 2. HISTORY controlled free-store memory control, improved type checking, and BCPL style single-line comments with two forward slashes (//). In C++, the basic 2.1. C data type is almost the same as C. In C++, there is one more type Booleans. The initial development of C occurred at AT&T Bell Labs between 1969 and A Boolean, bool, can have one of the two values true or false. A Boolean is 1973; (A Brief History of the C Language) according to Ritchie, the most used to express the results of logical operations. There are 32 keywords both creative period occurred in 1972. It was named "C" because its features were in C and C++ as shown. derived from an earlier language called "B".In 1978, Brian Kernighan and Dennis Ritchie published the first edition of The C Programming Language. auto else long switch This book, known to C programmers as "K&R", served for many years as an break enum register typedef informal specification of the language. The version of C that it describes is case extern return union commonly referred to as K&R C. The second edition of the book covers the char float short unsigned later ANSI C standard. K&R introduced several language features: const for signed void continue gotosizeof volatile Standard I/O library, default if static while longint data type, do intstruct double unsignedint data type, In C Language, There are four basic Date type. Only keyword _Packed is not used in C++ any more. There are 30 keywords that are not in C, but they are used in C++. Basic data type in C language (Brian et al. 1988). New keyword in C++. int “an integer, typically reflecting the natural size of asmdynamic_cast namespace reinterpret_cast integers on the host machine” bool explicit new static_cast float “single-precision floating point” catch false operator template double “double-precision floating point” class friend private this char “a single byte, capable of holding one character in const_cast inline public throw the local character set” delete mutable protected true try typeidtypename There are five Type Specifiers in C programming (Stephen, 2005) using a) long virtual wchar_t1 b) longlong c) short d) unsigned 2.3. Objective-C e) signed Objective-C was created primarily by Brad Cox and Tom Love in the early 1980s at their company Stepstone. Both had been introduced to Smalltalk There are lists of all the reserved keywords in C language. “These keywords while at ITT Corporation's Programming Technology Center in 1981. Cox was cannot be abbreviated, used as variable names, or used as any other type of intrigued by problems of true reusability in software design and identifiers” (C reserved keywords). programming. He realized that a language like Smalltalk would be invaluable in building development environments for system developers at ITT. Reserved keywords in C language (C reserved keywords) However, he and Tom Love also recognized that backward compatibility with C was critically important in ITT's telecom engineering milieu (Biancuzzi et al. auto else long switch 2009). Cox began writing a pre-processor for C to add some of the break enum register typedef capabilities of Smalltalk. He soon had a working implementation of an case extern return union do int object-oriented extension to the C language, which he called "OOPC" for char float short unsigned Object-Oriented Pre-Compiler (Cox, 1983). Love and Cox eventually formed a const for signed void new venture, Productivity Products International (PPI), to commercialize their product, which coupled an Objective-C compiler with class libraries. In 1986, continue gotosizeof volatile Cox published the main description of Objective-C in its original form in the default if static while double book Object-Oriented Programming, An Evolutionary Approach. In C, every data type such as a character, integer, or floating-point number has a range of values associated with it. The range is decided by the 3. INFLUENCES amount of storage that is allocated to store a particular type of data in the C is influenced by languages like Assembly, B (BCPL, CPL), ALGOL68, memory of the computer. It depends on the computer you’re running. This FORTRAN i.e., these languages helped in developing C. C is the parent feature for C language is called “machine-dependent”. For example, an language of many other languages or mostly of all the languages. Many later 12 integer might take up 32 bits on your computer, or perhaps it might be languages have borrowed directly or indirectly from C, including: C#, D, Go, stored in 64 bits on another computer. Don’t write any program that Java, Java Script, Limbo, LPC, Perl, PHP, Python, and Unix's C Shell. The most Page assumes the size of the data types in C (Brian et al. 1988). pervasive influence on these languages has been syntactical, and they tend to combine the recognizable expression and statement syntax of C with underlying type systems and data models that can be radically different. © 2013 Discovery Publication. All Rights Reserved. www.discoveryjournals.com OPEN ACCESS ANALYSIS ARTICLE Objective-C is influenced by C, Smalltalk. It is a powerful set of extensions to from C in terms of syntaxes, header files, some rules and many more things. the Standard ANSI C Language. It is designed & developed to give C full For example: - In C if return type of main ( ) is declared integer (int) then object-oriented programming capabilities, and to do so in a simple and return keyword must be used to return a value but in C++ no need to use straightforward way.JAVA, Objective-J & other languages have some features return keyword.C++ uses the objected oriented concepts that why it is also of it. C++ is influenced by C, Simula, Ada, etc. C adapts the features of known as Object Oriented Programming Language. In this language classes, inheritance, etc from Objective-C. C++ is firstly known as C with all the work is done in classes so making changes are much easier from C classes, later it gets its name C++. JAVA, ADA, PHP, C99, C# languages are language. influenced by it. 5. CONCLUSION 4. COMPARATIVE STUDY OF LANGUAGES This paper studies about the languages, their history, and influence of one In early times programming or coding is done with the help of binary digits. language to another. The purpose of developing C Language is to give All the characters have their binaries. In those days coding is very difficult programmer a coding friendly language. But this language has some because all the coding is done on binary or in assembly language. In these drawbacks also. To overcome these drawbacks new language Objective-C is languages memory register is directly used so remembering all the register derived. It is influenced by C. Objective-C also has some issues to overcome names and commands and binary values is not an easy work. If any changes these issues C++ is derived. It has features of C and Objective-C both. Since a programmer wants to do in that program then doing changes is much all these languages are derived from one another but they have some more difficult from making a new program. So programmer’s requires a dissimilarity also.C is a minimalistic programming language because it could language which minimise their task and make coding easier for them. After be compiled in a straightforward manner by a relatively simple compiler. C some time C Language was derived in 1970’s the purpose of discovering this offers low-level access to memory via pointers and the ability to access language is to make programming easier for programmer. In C Language specific hardware addresses. C generates only a few instructions of machine simple English is used for coding. No binaries as well as no need to languages for each of its core language elements and does not require remember the name of register. In C Language syntaxes are written in very extensive run-time support. It can be concluded that C language is suitable simple language which is easy to understand as well as to remember. C for many systems-programming applications that had traditionally been Language is derived from or influenced form the Assembly Language so it is implemented in assembly languages. \However, as C is structured oriented machine oriented or machine dependent i.e., the program can only run in programming language and focuses on the procedural programming that system on which it is design (Table 1). It cannot be port to any other paradigm, it is relatively hard to control the large-scale program. As C system which is having different configuration from the system on which it is language has high level and machine level mixed programming capacity, it is design. Other problem is that C Language is procedural language i.e., it has used in most hardware related applications. It is very suitable for writing its set rule for defining and declaring all the variables, functions, etc... For programs in embedded device, chip designing, industrial automation example first line of void main () is always used for variable declaration. All products and so forth and so on. Meanwhile, Software such as “Unix”, the variables are only declared in this line only not else anywhere in the “windows”, and other antivirus can also be created by C language. Last but program. By developing C Language problem of writing language is solved not at least, algorithm can also be implemented in C language easily. C++ but now some new problems are arises. To overcome these problems a new was originally designed to be an enhancement to C language. Basically it language is derived in 1980’s that is Objective-C Language. Objective-C inherits all the advantages of C language. In addition, it has more features Language is object oriented language. In this language no rules are than C, such as encapsulation, multiple inheritance, and Polymorphism. It can described. In this language there are no rules for name of variable, for be concluded that it is relatively easy to use C++ to develop a large or huge declaring variables or for doing any task. In this language printing is done system compared with C 44 language as C++ supports the object-oriented just by writing the sentence in square brackets. In this language all the work (OO) features. However, C++ has some disadvantages. C++ code is easily is done in classes that why it an object oriented language. But this language prone to errors related to data types because C++ does not offer very strong is not easy to learn or understand because in this there are no set rules for type-checking. C++ does not support platform independent. It can't run on defining any variable or function. But the advantage of this language is that it the all kinds of platforms. The main disadvantage is that C++ is not a pure gives the concept of objects. By using programming becomes very easy. object oriented programming language as it doesn’t have the feature of To overcome problems of Objective-C language new language is derived garbage collection. C++ adopts the pointers which lead to no security for the in 1980’s. With concept of object oriented and some predefined rules or data. C++ can be widely used in the software industry. As C++ can be a very functionalities a language is designed known as C with classes. Later this fast programming language after compiled, the software such as application language gets its originals name i.e., C++. C++ is a language which is semi software, device drivers and high-performance server can be designed by dependent on machine and which is easy to understand. C++ is different C++. Table 1 Comparative study of the languages Basis C Objective-C C++ Multi-paradigm, procedural, Paradigm(s) Imperative (Procedural), Structured Reflective, class-based object oriented object-oriented, functional, generic Appeared in 1972 1983 1985 Designed by Dennis Ritchie Brad Cox &Tom Love BjarneStroustrup Dennis Ritchie & Bell Labs(creators); ANSI BjarneStroustrup Bell Labs ISO/IEC Developer X3J11 (ANSI C);ISO/IEC Apple JTC1/SC22/WG21 JTC1/SC22/WG14(ISO C) File name extension .h, .c .h, .m, .mm .h, .hh, .cpp, .hpp, .cxx, .c++ Syntax Very complex Easiest Moderate Supports all types of inheritance Inheritance feature No such feature Supports all types of inheritance excluding multiple inheritance Emphasis on Functions Both( function & data) Data 13 Functions can be declared at the point of Totally class-based so function are Functions must be prototyped Function Declaration use declared in the classes before main Page Concept of overloading Doesn’t support overloading Supports overloading Supports overloading Header files Need to include them No need Need to include them © 2013 Discovery Publication. All Rights Reserved. www.discoveryjournals.com OPEN ACCESS ANALYSIS ARTICLE Concept of garbage For de-allocating memory delete ( For de-allocating memory free( ) is used Automatic garbage collection collection ) is used Keywords 32 12 98 Main( ) doesn’t automatically returns Main( ) automatically return Use of return keyword No concept of main( ) & return zero(0) zero(0) SUMMARY OF RESEARCH The paper is regarding the cumulative studies of three well known languages i.e.C,C++and Objective C.It comprises of all the characteristics ,advantages and disadvantages, and the developments of all the three languages . Also the paper helps to compare the languages on various aspects and helps us to decide where to use which language so as to obtain more potential output. FUTURE ISSUES 1. More developments in the field of languages and development work may add or deduce the comparisions. 2. Support for handling memory security vulnerabilities inlow-level programming. Can the pain in programming bereduced, and can ad hoc techniques be eliminated? DISCLOSURE STATEMENT There is no financial support for this research work from the funding agency. ACKNOWLEDGMENT Much thanks to our guide for his constructive criticism, and assistance towards the successful completion of this research work. REFERENCE 1. A Brief History of the C Language. Available athttp://hubpages.com 5. Brian W Kernighan, Dennis M Ritchie. Chapter 2; Types, Operators and /hub/A-Brief-History-of-the-C-Language (Accessed May 25th, 2010) Expressions in the C programming Language, Prentice-Hall Publishing, 2. A Brief History of C++. Available at http://hubpages.com/hub/A-Brief- 1988 History-of-the-C-Language (Accessed May 25th, 2010) 6. C reserved keywords. Available at http://publib.boulder.ibm.com/ 3. Online C++ tutorial, A Brief History of C++, available at http://www. infocenter/pdthelp/v1r1/index.jsp?topic=/com.ibm.debugtool.doc_8.1/e intap.net/~drw/cpp/cpp01_03.htm (Accessed May 25th, 2010) qa8ug02426.htm (Accessed April 20th, 2010). 4. Stephen G Kochan. Understanding Data Types and Constants in 7. Biancuzzi Federico, Warden Shane. Masterminds of Programming. Programming in C, Third Edition, Sams Publishing, 800 East 96th Street, O'Reilly Media, Inc. 2009, 242–246, ISBN 0-596-51517-0 Indianapolis, Indiana, 46240 USA, 2005, 23-39 8. Cox Brad. The object oriented pre-compiler: programming Smalltalk 80 methods in C language. ACM SIGPLAN Notices (New York, NY: ACM), 1983, 18(1).doi: 10.1145/948093.948095. Retrieved 2011-02-17 14 Page © 2013 Discovery Publication. All Rights Reserved. www.discoveryjournals.com OPEN ACCESS