home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / tutor / ctutor1 / intro.txt < prev    next >
Encoding:
Text File  |  1986-06-30  |  9.1 KB  |  191 lines

  1.                       Introduction to the C Tutorial
  2.  
  3.  
  4.              The programming language C, was originally developed by 
  5.  
  6.         Dennis  Ritchie of Bell Laboratories and was designed to run 
  7.  
  8.         on a PDP-11 with a UNIX operating system.   Although it  was 
  9.  
  10.         originally  intended  to run under UNIX,  there has  been  a 
  11.  
  12.         great  interest  in  running it under the  MS-DOS  operating 
  13.  
  14.         system and specifically on the IBM PC and  compatibles.   It 
  15.  
  16.         is an excellent language for this environment because of the 
  17.  
  18.         simplicity of expression,  the compactness of the code,  and 
  19.  
  20.         the wide range of applicability. 
  21.  
  22.              It  is  not a good "beginning" language because  it  is 
  23.  
  24.         somewhat cryptic in nature.  It allows the programmer a wide 
  25.  
  26.         range of operations from high level down to a very low level 
  27.  
  28.         approaching the level of assembly language.   There seems to 
  29.  
  30.         be no limit to the flexibility available.  One experienced C 
  31.  
  32.         programmer made the statement,  "You can program anything in 
  33.  
  34.         C", and the statement is well supported by my own experience 
  35.  
  36.         with  the  language.    Along  with  the  resulting  freedom 
  37.  
  38.         however,  you take on a great deal of responsibility because 
  39.  
  40.         it is very easy to write a program that destroys itself  due 
  41.  
  42.         to  the  silly little errors that the Pascal  compiler  will 
  43.  
  44.         flag  and call a fatal error.   In C,  you are very much  on 
  45.  
  46.         your own as you will soon find.
  47.  
  48.              Since C is not a beginners language,  I will assume you 
  49.  
  50.         are  not a beginning programmer,  and I will not attempt  to 
  51.  
  52.         bore you by defining a constant and a variable.  You will be 
  53.  
  54.         expected to know these basic concepts.   You will,  however, 
  55.  
  56.         be  expected to know nothing of the C programming  language.  
  57.  
  58.         I  will begin with the most basic concepts of C and take you 
  59.  
  60.         up  to  the  highest level of C  programming  including  the 
  61.  
  62.         usually intimidating concepts of pointers,  structures,  and 
  63.  
  64.         dynamic allocation.   To fully understand these concepts, it 
  65.  
  66.         will  take a good bit of time and work on your part  because 
  67.  
  68.         they  not  particularly easy to grasp,  but  they  are  very 
  69.  
  70.         powerful tools.   Enough said about that, you will see their 
  71.  
  72.         power when we get there,  just don't allow yourself to worry 
  73.  
  74.         about them yet.
  75.  
  76.              Programming  in C is a tremendous asset in those  areas 
  77.  
  78.         where you may want to use Assembly Language but would rather 
  79.  
  80.         keep it a simple to write and easy to maintain program.   It 
  81.  
  82.         has been said that a program written in C will pay a premium 
  83.  
  84.         of  a 50 to 100% increase in runtime because no language  is 
  85.  
  86.         as compact or fast as Assembly Language.   However, the time 
  87.  
  88.         saved  in  coding  can be tremendous,  making  it  the  most 
  89.  
  90.         desirable   language  for  many  programming   chores.    In 
  91.  
  92.         addition,  since  most  programs spend 90 percent  of  their 
  93.  
  94.         operating time in only 10 percent or less of the code, it is 
  95.  
  96.         possible  to  write  a program in C,  then rewrite  a  small 
  97.  
  98.         portion  of the code in Assembly Language and  approach  the 
  99.  
  100.  
  101.  
  102.                                   Page 1
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.                       Introduction to the C Tutorial
  113.  
  114.  
  115.         execution  speed  of  the same program if  it  were  written 
  116.  
  117.         entirely in Assembly Language.
  118.  
  119.              Approximately 75 percent of all new commercial programs 
  120.  
  121.         introduced  for the IBM PC have been written in C,  and  the 
  122.  
  123.         percentage   is   probably  growing.    Microsoft   recently 
  124.  
  125.         introduced a new Macro Assembler, version 4.0, and they said 
  126.  
  127.         that it was written in C.  There are probably a few routines 
  128.  
  129.         coded in Assembly Language,  but the majority was written in 
  130.  
  131.         C. 
  132.  
  133.              Since C was designed essentially by one person, and not 
  134.  
  135.         by  a committee,  it is a very usable language but  not  too 
  136.  
  137.         well defined.   There is no standard for the C language, but 
  138.  
  139.         the   American  National  Standards  Association  (ANSI)  is 
  140.  
  141.         developing a standard for the language at which time it will 
  142.  
  143.         follow  rigid rules.   It is interesting to  note,  however, 
  144.  
  145.         that  even  though  it  does  not  have  a   standard,   the 
  146.  
  147.         differences between implementations are very small.  This is 
  148.  
  149.         probably  due  to  the  fact that  the  original  unofficial 
  150.  
  151.         definition  was  so well thought out and  carefully  planned 
  152.  
  153.         that  extensions to the language are  not  needed.   Pascal, 
  154.  
  155.         which  has  a rigorous definition,  has many  extensions  by 
  156.  
  157.         compiler  writers  and every extension is  different.   This 
  158.  
  159.         leads  to a real problem when transporting a Pascal  program 
  160.  
  161.         from one computer to another.
  162.  
  163.              Even  though the C language enjoys a good  record  when 
  164.  
  165.         programs are transported from one implementation to another, 
  166.  
  167.         there  are differences in compilers as you will find anytime 
  168.  
  169.         you  try to use another compiler.   Most of the  differences 
  170.  
  171.         become apparent when you use nonstandard extensions such  as 
  172.  
  173.         calls  to  the DOS BIOS,  but even these differences can  be 
  174.  
  175.         minimized by careful choice of programming means. 
  176.  
  177.              Your first problem will not be how to program in C, but 
  178.  
  179.         how to use your particular compiler.   Since there are  over 
  180.  
  181.         20 good compilers available, there is no way I can cover the 
  182.  
  183.         operation of all compilers.  Notes about a few of the better 
  184.  
  185.         known  compilers are given in the "COMPILER.DOC" file on the 
  186.  
  187.         distribution  diskette.   Read the documentation  that  came 
  188.  
  189.         with  your  compiler  to  learn how to  compile  and  run  a 
  190.  
  191.         program.
  192.  
  193.               One  last note about compilers.   I wrote a moderately 
  194.  
  195.         large program in C that was composed of about 1200 lines  of 
  196.  
  197.         source code contained in 4 separately compiled files.  I was 
  198.  
  199.         initially   using  a  very  inexpensive  compiler  from  MIX 
  200.  
  201.         Software of Richardson,  Texas that sells for $39.95.   This 
  202.  
  203.         compiler  did  everything I ever asked it to do and  did  it 
  204.  
  205.         well,  including floating point numbers.   In addition,  the 
  206.  
  207.  
  208.  
  209.                                   Page 2
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.                       Introduction to the C Tutorial
  220.  
  221.  
  222.         compile  times  were  extremely short and  there  were  many 
  223.  
  224.         extensions  to the basic language as defined by  Kernigan  & 
  225.  
  226.         Ritchie.   In short, the compiler was a good implementation.  
  227.  
  228.         Later,  I  switched over to a Lattice C compiler that  sells 
  229.  
  230.         for  $500.00.   It  took a bit of work because  the  Lattice 
  231.  
  232.         compiler  did  not  have  as  many  extensions  as  the  MIX 
  233.  
  234.         compiler.   The  Lattice  compiler  also  took  considerably 
  235.  
  236.         longer to compile,  probably 2 to 3 times as long.   The big 
  237.  
  238.         difference in the two compilers was in the execution time of 
  239.  
  240.         the program which read in a file,  did a lot of searching in 
  241.  
  242.         memory, and displayed the results on the monitor.  The final 
  243.  
  244.         MIX program took 95 seconds to complete all operations,  and 
  245.  
  246.         the  Lattice  compiled  program  took  only  10  seconds  to 
  247.  
  248.         complete.   I should add that the MIX compiler has a speedup 
  249.  
  250.         utility  that  increases the speed by a factor of  about  8, 
  251.  
  252.         according  to one independent review,  getting the speed  of 
  253.  
  254.         the MIX program in the range of the Lattice program.  (I did 
  255.  
  256.         not  try the speedup program on this particular file.)   The 
  257.  
  258.         MIX  compiler  missed  several  subtle  type  errors  during 
  259.  
  260.         compile  that  were  flagged  as  warnings  by  the  Lattice 
  261.  
  262.         compiler.   Due  to  the nature of that particular  program, 
  263.  
  264.         either  run-time  would be acceptable and  therefore  either 
  265.  
  266.         compiler would be acceptable.
  267.  
  268.              The  above  paragraph  was  given only to  aid  you  in 
  269.  
  270.         selecting  a  compiler.    The  Lattice  compiler  is   very 
  271.  
  272.         difficult  to use for an inexperienced programmer,  but  has 
  273.  
  274.         very few limitations.   The MIX compiler, on the other hand, 
  275.  
  276.         was  very easy to set up and begin using,  and would be very 
  277.  
  278.         appropriate for  most "hobby" computing.   Depending on your 
  279.  
  280.         application,  the  most expensive is probably not the  best.  
  281.  
  282.         In this case,  the MIX compiler would be great for  learning 
  283.  
  284.         the language and for many applications. 
  285.  
  286.              Consult  the  COMPILER.DOC  file  for  notes  on  other 
  287.  
  288.         compilers  and  recommendations  on  what  compiler  may  be 
  289.  
  290.         suitable for your purposes.
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.                                   Page 3
  308.  
  309.