home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug063.arc / INTRO.TXT < prev    next >
Text File  |  1979-12-31  |  9KB  |  191 lines

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