flavors of c

8
 . Flavors of C C comes into 2 versions, C89 and C99. The number after the alphabet represents the year in which the ISO/ANSI Standard for the language was adopted.  As you can guess, C89 standard was developed in year 1989 and C99 standard was adopted in C89 also includes the features added to the language in year 1995 as Amendment 1. C99 is superset of C89. That means all the features available in C89 are also available in C99. This is generally true but there is some incompatibiliti es in both the versions and C99 discard some obsolete features of C89.C99 mainly expanded C89 by adding new innovative features and huge numeric libraries.  In all tutorials clear distinction between C89 and C99 will be maintained as knowing difference between C89 and C99 is part of being a top notch programmer.  Although C99 added many Innovative features you would like to restrict your code only to C89 because even though a lot of time has passed since C99 was release the C compilers available for C have still not incorporated it into their structure. Its C89 code which most C compilers are able to compile. C89 is also widespread language than C99 and generally considered to be C.Also the famous language C++ is formed from C89 so you will not able to compile C99 code on a C++ Compiler even though you can use it to c ompile a C89 code. 2. History of C C was invented by Dennis Ritchie and first implemented by him on a DEC PDP ± 11 based on a Unix O.S. C was influence by a language called B which was invented by Ken Thompson.  First book ever written on C was µThe C Programming Language¶ by Dennis Ritchie and Brian Kernighan.  First standard of C was adopted in 1989 by ANSI/ISO.  An Amendment was added to C language in year 1995. Second standard of C was adopted in year 1999 by ANSI/ISO. 3. ISO/ANSI Standard  ISO stands for International Standard Organization  ANSI stands for American National Standard Institute.  For many years de facto standard of C was provided with UNIX but as the variety of systems and O.S. increased each of the provided its own version of C language. This became big problem as many variant of same language came into existence simultaneously, creating a chaos. Then came ANSI/ISO organizations which standardize the C language and every variant has to obey these standards hence most general and essential part became common to all. Standard created a programming syntax and library (set of functions) which every compiler of C language was compulsory to include.All the compilers presently contain complete standard C and much more. As standard C is

Upload: kumar-swamy

Post on 08-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Flavors of C

8/7/2019 Flavors of C

http://slidepdf.com/reader/full/flavors-of-c 1/8

 . Flavors of C 

C comes into 2 versions, C89 and C99.

The number after the alphabet represents the year in which the ISO/ANSI Standard for the language was adopted.

 As you can guess, C89 standard was developed in year 1989 and C99 standard was adopted in C89 also includes

the features added to the language in year 1995 as Amendment 1.

C99 is superset of C89. That means all the features available in C89 are also available in C99. This is generallytrue but there is some incompatibilities in both the versions and C99 discard some obsolete features of C89.C99

mainly expanded C89 by adding new innovative features and huge numeric libraries.

 In all tutorials clear distinction between C89 and C99 will be maintained as knowing difference between C89 and 

C99 is part of being a top notch programmer.

 Although C99 added many Innovative features you would like to restrict your code only to C89 because even though

a lot of time has passed since C99 was release the C compilers available for C have still not incorporated it into

their structure. Its C89 code which most C compilers are able to compile. C89 is also widespread language thanC99 and generally considered to be C.Also the famous language C++ is formed from C89 so you will not able to

compile C99 code on a C++ Compiler even though you can use it to compile a C89 code.

2. History of C 

C was invented by Dennis Ritchie and first implemented by him on a DEC PDP ± 11 based on a Unix O.S.

C was influence by a language called B which was invented by Ken Thompson.

 First book ever written on C was µThe C Programming Language¶ by Dennis Ritchie and Brian Kernighan.

 First standard of C was adopted in 1989 by ANSI/ISO.

 An Amendment was added to C language in year 1995.

Second standard of C was adopted in year 1999 by ANSI/ISO.

3. ISO/ANSI Standard 

 ISO stands for International Standard Organization

 ANSI stands for American National Standard Institute.

 For many years de facto standard of C was provided with UNIX but as the variety of systems and O.S. increased 

each of the provided its own version of C language. This became big problem as many variant of same languagecame into existence simultaneously, creating a chaos. Then came ANSI/ISO organizations which standardize the C 

language and every variant has to obey these standards hence most general and essential part became common to

all.

Standard created a programming syntax and library (set of functions) which every compiler of C language was

compulsory to include.All the compilers presently contain complete standard C and much more. As standard C is

Page 2: Flavors of C

8/7/2019 Flavors of C

http://slidepdf.com/reader/full/flavors-of-c 2/8

very limiting, for example no graphics or interrupts access function are defined in standard C but your compiler will 

be having them for sure because they form an essential part of programming.

 Last point to mention is that if you want your code to portable to large number of operating systems and compilers

 you should restrict your code to standard C.

4 . Middle Level Language

 All the programming languages are divided into 3 levels

 A.   H igh Level Language B.   Middle Level Language

C.   Low Level Language

 H igh Level Languages ± These languages are more oriented to be user friendly and syntax nearly approaches

 English. They have poor efficiency and flexibility.

 Low Level Languages ± These languages are computer or machine oriented. They allow programmer to code with

maximum efficiency and flexibility but coding is quite tough. Its syntax nearly approaches the binary language.

 Middle Level Language ± The middle level languages is one which combines best feature of both high and low level 

languages. They are easy to code as well as efficient and flexible.

C is a middle level language.

 Example ± 

 H igh Level ± Basic, Pascal, COBOL, FORTRAN 

 Middle Level ± C, C++, Java, C# 

 Low Level ± Assembly Language

5  . Portability

 Portability means by definition means that ability to adapt code written one programming environment onto

another.

 In Laymen terms it means that if you compile or designed a program in Windows and wish to run it in Linux or Dosand it does run then code is said to be portable in the two environments and can be use interchangeably without any

code modification.

 Low Level Language code is not portable generally while its easy portable for  H igh Level Language.

Code generated by C is also very portable even though it has its limitations which should be kept under 

consideration. This not a disadvantage keeping in mind that c allows us to do system level programming. That is it 

 gives us the ability to modify bits, bytes, and words the basic identities through which a computer operates.

To make your code most portable you must restrict it to Standard C.

6. Structured Language

Page 3: Flavors of C

8/7/2019 Flavors of C

http://slidepdf.com/reader/full/flavors-of-c 3/8

C is a structured Language.

 It represents the philosophy of programming use such as Block-Structure in FORTAN and OOP (Object Oriented 

 Programming) in C++.

The main feature of Structure Language is compartmentalization of code.

This philosophy allows C to handle far more complexity than its predecessors. C can easily handle code up to 10000

lines.

Compartmentalization of code means ability of one section of code to completely hide itself from other section of 

codes.In C Compartmentalization of Code is achieved by deploying subroutines. Each subroutine is a stand alone

code. It¶s completely separate from other subroutines. It takes input data as parameters, process them, do its job

and return the result as output. As a result no side effect is caused the program.

 It also facilitates the reusability of code as same code could be used in variety of programming situations and could 

be easily inserted into another program.

C does not have a strict field concept this means that you can place code anywhere on a line.In C end of 

 programming line is made by a semicolon.

Structure languages support many loop constructs such as for, do, while etc and use of goto generally discouraged 

in structure language while goto form a very essential part of a non structured language such as FORTAN, COBOL

and Basic.

Structure Language also have concept of library. Library consists of large number of subroutines and can act asbuilding blocks of a program. These blocks acts like bricks which when cemented together can form a huge

 skyscraper.

This programming approach is also called a top - down approach. In this main algorithm is broken in to small parts

and each part is coded separately.

 In nutshell Structure programming approach give programmer capability to code an algorithm efficiently, clearly

with elegance and conceptualize true meaning of the algorithm.

7  . Compilers Vs. Interpreters

There are two general ways a program can be converted from source code into object code it can be compiled or 

interpreted.

 In layman terms it can be call the ways through which an code can be converted into a computer readable format 

 from a human readable format.

Generally a programming language is designed keeping in mind one of the above methodologies. For example youcan say that Java was designed to be interpreted and Pascal for compilation.

C was designed for Compilation.

 Irrespective of design any language can be compiled or interpreted but efficiency can vary in both processes for 

 same code.

Page 4: Flavors of C

8/7/2019 Flavors of C

http://slidepdf.com/reader/full/flavors-of-c 4/8

Compiler and Interpreter main difference is in the way they read your source code.Interpreter reads source code

one line at a time and then convert it to respective object code while compiler reads source code completely in one

reading and convert it into respective code.

 A compiler takes more time in conversion than an interpreter.

 A Compiled program runs faster than a interpreted program.

8 . Object Code Vs. Source Code

The Programming code created by the user is known as source code.

The Programming code generated by the Complier\Interpreter is known as object code.

Source Code is in human readable format.

Object Code is in computer readable format.

Source Code is Input to a Compiler\Interpreter while object code is Output of a Compiler/Interpreter.

Source Code is in Text Format While Object code is in Binary Format.

9. Compile Time Vs Runtime

Compile Time is the time for which program is compiled.

 Run Time is the time for which program is interpreted.

Static Programming is done at compile time while dynamic programming such as DMA (Dynamic Memory

 Allocation) is done at Runtime.

10. Linker 

 In general all c compilers come with a library which includes standard library and much more. You use this

 functions more frequently than any thing else.

 In general when compiler come across a reference of library function in your code while compiling it remembers its

name and leave a space holder for its code.

 Now when Compilation is complete it¶s the job of a linker to link the object code of your program with object code

of library functions.

These functions object code are in relocatable format and real physical memory is allocated to them only by

compiler. Initially only offset Information is stored.

 Linker is also used in process of separate compilation in this program have subroutines spread over more than one

 file. Each of these files are separately compiled and its linker¶s job to resolve unknown references.

 Linker can be stand alone , with the compiler or provide by you Operating System.

Page 5: Flavors of C

8/7/2019 Flavors of C

http://slidepdf.com/reader/full/flavors-of-c 5/8

11. Integrated Development Environment (IDE)

 Integrated Development Environment is the in thing. It is combination of editor, Linker, Compiler and interpreter in

one big bundle software.

 Programs are quickly developed in these IDEs. They provide shortcut to every function and you don¶t have to leave

even one window.

Otherwise you would be writing a program in notepad, compiling it on command line and then linking it an then

executing the compiled result to find the output and so on. This could pretty cumbersome.

 Also debugging that is finding errors in a program is also quite easy in an IDE.

There are many IDEs available on net I would recommend Turbo C++ 3.0. It is one of the oldest compilers yet the

interface it provides for learning is unbeatable even by the most recent compilers. It is a dos based compiler and the

one on which budding programmers should start their programming experience.

Turbo C++ 3.0 also provides BGI graphics which are now obsolete, yet are most effective in learning Games or 3D

 Programming because of their easy syntax.

12. Role of main

 Like jigsaw puzzle, made up of many pieces, C Program is made up of one or more functions.

 For a function to be validly compile function that must be present should be main (). It is the entry point of your 

 program or in other words the first function to be compiled by your program.

 In general main forms an outline of the program formed by function calls. The functions can call more functions or 

even themselves by process of recursion.

 Main can also be code to accept arguments from command line which we will be discussing in future tutorials.

General form of main is ± 

int main ( ) // Avoid using void main ( ) special thanks to Salem and vart from C Bo

{

f1 ( );

f2 ( );

««

return 0;

}

13. Keywords

 Keywords are some words reserved by C. They when combine with C Syntax forms C Programming Language.

There are 32 keywords in C89 and 37 keywords in C99. C99 adds five new keywords to the original language.

C89 Keywords ± 

Page 6: Flavors of C

8/7/2019 Flavors of C

http://slidepdf.com/reader/full/flavors-of-c 6/8

auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register,

return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while.

 Additional C99 Keywords ± 

 _Bool, _Imaginary, restrict, _Complex, inline.

You cannot have identifier name same as a c keyword that is why they are called reserved words.

 Also try not to name your identifiers as library functions or as main otherwise it may lead to a name collision.

One point worth mentioning is C is Case-Sensitive that is in this upper case and lower case are considered to be

different this means go is a keyword while GO is not.

14 . Standard Library

You can easily write program from just keywords but that would have very limited capabilities as C provide no

keywords for input/output, graphics etc.

 In C this achieved with help of Library functions. Every compiler comes with a gigantic library completely covering 

 standard library and this library is the real power of C.

You would be relying on this library for almost everything in your program.

Standard Library has more or less 180 functions under 24 header files which form the backbone of c programming 

language. You can find detailed reference of each of the program inour C Standard Library Section.

15  . Memory Map

 A compile C program generates 4 memory regions which it uses during its life time.

 A.  Stack 

 B.   H eap

C.  Global Variables

 D.   Program Code

Stack is used for many purposes such as holding local variables, program state, function calling and much more.

 H eap is a region of free memory which can be used by your program through Dynamic Memory Allocation.

Global Variables refer to the data you have put I global namespace and they retain their identity till program

terminates.

 Program Code is your object; in this memory region it is stored.

16. C and C++

They most common question newcomers asked are what relation between C and C++ ?

C++ is superset of C. It means C++ incorporates entire C language with some minor incompatibilities.

Page 7: Flavors of C

8/7/2019 Flavors of C

http://slidepdf.com/reader/full/flavors-of-c 7/8

You can use a C++ compiler to compile C code but you should ensure that file extension .c not .cpp. This extension

tells a C++ compiler to do C compile on your source code.

Sadly this website is purely dedicated to C and not C++.

17  . Why learn C?

Well why learn C this most important topic in this website so here is a little article I wrote a while ago to clear 

 your doubts permanently.

10 Reasons - Why C Should Be Your First Programming Language

To a beginner programmer the biggest question is where to start. Which language to choose from the mighty pool of 

100's of languages.This is was the same question I asked myself when I started writing my first program. I tried many languages but 

 finally I came to C, the most beautiful and charming language of all. I was literally blown away by the simplicity

and elegance of C.

Though C is simple it is one of the most powerful languages ever created.

 In this dynamic IT world new language come every day and get obsolete, so there must be something in the C whichhas remained there for 3 decades and more and even today there is hardly any language which can match its

 strength.

90% of the starting programmer says that C has been superseded by its predecessors such as C++, Java, and C # 

and so on so why learn C. I don't know why they think so but I know one thing that they will never excel the other 

10% programmers who differs from this opinion. Simple reason is how could a skyscraper building stand against 

time if its foundation is not strong.

 Now Let us begin to analyze reason why C should be your first programming language.

1. I believe nobody can learn C++ or Java directly. To master these languages you need to have a strong concept of 

 programming element such as polymorphism, classes, inheritance etc. Simple question is how you can learn such

complicated concepts when you don't even know about the basic elements such as block functions. C is a language

which begins from scratch and it has foundational concepts on which today concepts stand on.

2. It is language on which C++ is based on, hence C# also derive its origin from the C. Java is also a distant cousinof C and share the same programming concept and syntax of C. These are the most dominant languages in the

world and all are based on C. To rock the world through them you must get rocking with C.

3. C++, Java, and C # make use of OOP (Object Oriented Programming). Not all programs need it even though it is

a powerful tool. Such programs are still written in C.

4. When ever it comes to performance (speed of execution), C is unbeatable.

5. Major parts of the Windows, Unix and Linux are still written in C. So if you want program these OS or create

 your own you need to know C.

6. Device drivers of new devices are always written in C. The reason is that C provides you access to the basic

elements of the computer. It gives you direct access to memory of your CPU through pointers. It allows you to

manipulate and play with bits and bytes.

Page 8: Flavors of C

8/7/2019 Flavors of C

http://slidepdf.com/reader/full/flavors-of-c 8/8

7. Mobiles, Palmtops, PDA's etc are gaining popularity every second. Also appliances such as T.V., Refrigerators,

and Microwaves etc. are becoming an integral part of our daily needs. You may not know but they have a CPU with

them which do need programming and the software's written for them are known as embedded system programs.

These programs have to be fast in execution but also have a very little memory. No question why C is ideally suited 

 for embedded system programming.

8. You must have played games on your PC. Even today these astounding 3D games use C as their core. Why? The simple reason who will play the game when it takes a lot of time fire a bullet after you have given command from the

console. The reply to the command should be damn prompt and fast. Reply in 1 Nano second is an outstanding 

 game; Reply in 10 Nano seconds is crap. Even today there is no match for C.

9. C is a middle level language. There are three types of language -  H igh Level, Middle Level & Low Level.  H igh

level languages are user oriented, giving faster development of programs, example is BASIC. Low level languages

are machine oriented; they provide faster execution of programs. C is a middle level language because it combines

the best part of high level language with low level language. It is both user and machine oriented and provides

infinite possibilities.

10. Last but not least it is a block structured language. The first symbol of a modern language is that it is block 

 structured. Each code exists in separate block and is not known to code in other block providing easy means of 

 programming and minimizing the possibilities of undesirable side effects. C is designed from the base to top to be ablock structured language. Many older languages, most popular being BASIC tried to introduce this concept but their short coming can never fulfilled as they were never built along these line.

 I think I have given all reason I know why c should be your first programming language. One thing is for sure that 

there no other language which more reliable, simple and easy to use.