home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 137_01 / apr84col.ddj < prev    next >
Text File  |  1979-12-31  |  19KB  |  484 lines

  1. .pl 61
  2. .po 0
  3. ..
  4. .. this article was prepared for the C/Unix Programmer's Notebook
  5. .. Copyright 1984 Pyramid Systems, Inc.
  6. ..
  7. .. by A. Skjellum
  8. ..
  9. .he "C/Unix Programmer's Notebook"   for April 1984 DDJ. 
  10.  
  11.  
  12.                                Introduction
  13.  
  14.     Readers  responded to my December,  1983,  column where I discussed 
  15.  
  16. perceived  deficiencies in the Unix operating system.   Their comments  are 
  17.  
  18. included here in part.
  19.  
  20.     The  follow-up  discussion  on runtime libraries  and  link  format 
  21.  
  22. incompatibilities are also presented here.
  23.  
  24.     It  was also my intention to discuss two C compilers which  support 
  25.  
  26. the  large memory  concept on the 8086.   One of the compilers has not  yet 
  27.  
  28. been  received,  so this comparative review will have to be included  in  a 
  29.  
  30. future column.
  31.  
  32.     I have received several more letters concerning C layout standards.  
  33.  
  34. While  we  don't  have room to include their  comments  at  present,  their 
  35.  
  36. comments will undoubtedly lead to several columns concerning related topics 
  37.  
  38. of interest.  
  39.  
  40.                             Comments about Unix
  41.  
  42.     In the December column,  I mentioned several aspects of  Unix which 
  43.  
  44. I believe constitute weaknesses.   Tony LiCausi of Canoga Park, California, 
  45.  
  46. sent me a letter with his dissenting opinions.  He begins by remarking:
  47.  
  48.     "Unix was designed for the programming environment, for use by folk 
  49. already  familiar with computers.   Unnecessary I/O slows down a  program's 
  50. performance and hence should be eliminated.   Thankfully verbosity is often 
  51. eliminated,  in Unix,  as the default option.  However many of the programs 
  52. do  have  command line switches to increase the progress reporting  of  the 
  53. program."
  54.  
  55.     Unix  was  designed to circumvent the flaws of  existing  operating 
  56.  
  57. systems. Under Unix, modular programs are coupled via pipelines to create a 
  58.  
  59. convenient   working   environment   and  reduce  repetition   of   effort.  
  60.  
  61. Furthermore,  Unix  offers unequalled portability between large  and  small 
  62.  
  63. computer  systems.   Since  it  is successful  in  these  respects,  Unix's 
  64.  
  65. popularity  is growing.   Hence,  more and more computer users are  gaining 
  66.  
  67. access  to machines which use Unix.   Many of these users are familiar with 
  68.  
  69. computers  and programming while others are novices to both  computing  and 
  70.  
  71. Unix.  
  72.  
  73.     Let's  assume that a user is well-versed in programming but is  new 
  74.  
  75. to  Unix.   According  to Mr.  LiCausi,  this user belongs to the group  of 
  76.  
  77. people  for  whom  Unix was designed.   I'll assume that the  user  has  an 
  78.  
  79. application  in mind,  since the average user won't be writing programs  as 
  80.  
  81. ends unto themselves.  To succeed in implementing his application, the user 
  82.  
  83. will have to learn about various aspects of Unix,  including various  shell 
  84.  
  85. commands, system calls, and runtime libraries.  However, I submit that this 
  86.  
  87. type  of user will be slowed down significantly by overall poor quality  of 
  88.  
  89. the Unix documentation.  Since examples in the Unix documents are typically 
  90.  
  91. both terse and highly complicated, the typical user could spend an enormous 
  92.  
  93. amount of time circumventing a single snag.  
  94.  
  95.     Imagine  linking  the mathematical function library as part of a  C 
  96.  
  97. compilation.  Two seemingly possible ways for doing this are:
  98.  
  99.         cc -o test test.c -lm
  100.  
  101. or
  102.  
  103.         cc -lm -o test test.c
  104.  
  105. It  turns out that the former method is correct while that latter  produces 
  106.  
  107. undefined  function  error messages at  the  linker  stage.   However,  the 
  108.  
  109. documentation  does not indicate that the '-lm' must be near the end of the 
  110.  
  111. line.  
  112.  
  113.     Our  hypothetical  user  will also be slowed down  by  the  cryptic 
  114.  
  115. nature  of error messages.   It is true that the more  sophisticated  users 
  116.  
  117. require  little or no prompting,  and only gentle nudges when they make  an 
  118.  
  119. incorrect  entry,  but the vast majority of users probably don't belong  to 
  120.  
  121. this category.
  122.  
  123.  
  124.     Finally,  the  user  will  be slowed down by inexplicable  and  un-
  125.  
  126. documented bugs in systems such as troff and eqn which I mentioned  before.   
  127.  
  128. Furthermore,  circumventing bugs requires highly specific knowledge.  Also, 
  129.  
  130. the  solutions,  even if available,  may not be widely known.   On the Unix 
  131.  
  132. machine I use,  only a small group of people are aware of the procedure for 
  133.  
  134. avoiding some common, but annoying, bugs in eqn. 
  135.  
  136.     Mr. LiCausi makes a very valid point concerning this:
  137.  
  138.     "Software  bugs are not acceptable in any form at any  time.   Unix 
  139. from  Bell Labs is sold as unsupported software.   Their attitude is,  'OK, 
  140. we'll  sell it to you but,  we don't want to here from you.'  There  is  no 
  141. mechanism  to  report or correct bugs at the source.   Source code  is  not 
  142. typically  available to the average user.   Source code is guarded on  Unix 
  143. like gold;  just like any other commercial software.  Having done debugging 
  144. of  the f77 compiler on one system,  access to other software (for  example 
  145. and integration) was severely limited."
  146.  
  147.     Thus,  while Mr. LiCausi contends that Unix was designed for people 
  148.  
  149. with programming experience, he sets his standard for 'unnecessary I/O' and 
  150.  
  151. 'program  performance' based on the most sophisticated level of Unix  user.  
  152.  
  153. Furthermore, it is still not clear to me why the sophisticated users should 
  154.  
  155. be more willing to stand for poor quality documentation and user-unfriendly 
  156.  
  157. software  than every-day users.   Finally,  it is not at all apparent to me 
  158.  
  159. from  practical  experience  that 'many' of  the  standard  shell  commands 
  160.  
  161. support extended progress reporting. 
  162.  
  163.     Mr. LiCausi goes on to state:
  164.  
  165.     "The secret society of Unix is partially the result of the paranoia 
  166. of  'unauthorized access.'  The remainder is due to the lack of  commercial 
  167. incentive.   The  incentive has obviously increased as can be evidenced  by 
  168. the proliferation of books and articles on Unix anc C."
  169.  
  170.     I  stated in my previous column that some users perceive Unix as  a 
  171.  
  172. secret society.  This is the case because they cannot grasp certain aspects 
  173.  
  174. of  its  operation  based on the written and on-line  documentation  alone.  
  175.  
  176. Only through initiated members can the knowledge (and undocumented  tricks, 
  177.  
  178. patches  etc.)  be obtained.   Thus people feel left  out.   Other  popular 
  179.  
  180. operating  systems do not have the same aura as Unix.   For  example,  CP/M 
  181.  
  182. users  are  not  considered a 'secret society' even though  CP/M  has  non-
  183.  
  184. trivial  aspects.   Furthermore,  minicomputer  operating systems  such  as 
  185.  
  186. VAX/VMS  (DEC) and AOS/VS (Data General) don't have the mysterious  quality 
  187.  
  188. of  Unix.   That's because they have much more documentation to explain the 
  189.  
  190. nitty-gritty of using the system.  
  191.  
  192.     Mr. LiCausi finishes by stating:
  193.  
  194.     "Unix  is not user-unfriendly.   Admittedly it is beginner hostile.  
  195. Changes will be required to adopt Unix en masse,  ie for the micro,  but  I 
  196. hope that it does not spell the end of 'silent' software."
  197.  
  198.     My final counter-remark is that most users never become sufficently 
  199.  
  200. sophisticated  in enough diverse aspects of Unix to escape the  feeling  of 
  201.  
  202. user-hostility.   I personally run into difficulties, even though I've used 
  203.  
  204. Unix for almost four years.  As soon as I use aspects of Unix which are not 
  205.  
  206. part of my daily routine, 'gottchas' appear.
  207.  
  208.                            Other Points of View
  209.  
  210.     H.T. Gordon sent in a letter concerning Unix.  He writes:
  211.  
  212.     "It  was a pleasure to read the Skjellum critique of [Unix] in  DDJ 
  213. #86.   Since  C/Unix  is becoming the sacred cow of the computer  Brahmins, 
  214. few have the courage to point out its flaws.  It was designed by one of the 
  215. elite,  for elite users.  To them it's concise and elegant, even 'obvious.'  
  216. Only  rarely  is any explanation needed.   If it is,  a terse one will  do.  
  217. Prophets inspired by the high gods cannot waste their time spelling  things 
  218. out for mere morals in words of one syllable."
  219.  
  220.     I  don't  think that the state of C/Unix is as bad  as  Mr.  Gordon 
  221.  
  222. suggests.   While there are problems,  I think that Unix has many strengths 
  223.  
  224. and these strengths will be the basis for future operating systems.   It is 
  225.  
  226. the  purpose  of this column to discuss strengths and weaknesses of  C  and 
  227.  
  228. Unix  and  to propose solutions as well as to point out  the  problems.   I 
  229.  
  230. encourage  readers  to  pose  solutions to these and  other  problems  they 
  231.  
  232. perceive.
  233.                         Low level Input-Output in C
  234.  
  235.     Patrick Cawood of Los Angeles writes:
  236.  
  237.     "I read with great interest your last article on tendencies in Unix 
  238. to produce poor operator interaction programs.   I seem to have met some of 
  239. the same in C."
  240.  
  241.     "In order to provide a secure operator interface, one does not echo 
  242. a keyboard character to the screen until it has been examined and  approved 
  243. by the program. But getch() function automatically echoes--even line feeds, 
  244. up arrows,  etc.!!   Function putch() provides an automatic line feed after 
  245. printing on the screen!!
  246.  
  247.     He goes on to state:
  248.  
  249.     "I  simply cannot believe that anyone would wittingly design  these 
  250. functions as they are,  or not provide any alternative hardware interfaces.  
  251. Especially  considering   some of the tasks I've heard were written  in  C.  
  252. But  perhaps these people writing serious software were all forced to write 
  253. their own hardware interfaces."
  254.  
  255.     The problem which Mr.  Cawood is referring to exists in a number of 
  256.  
  257. non-Unix C compilers.   To begin with, let's review the problem in the Unix 
  258.  
  259. environment.   Under  Unix,  putc() and getc() acquire and return a  single 
  260.  
  261. character respectively.  However, to offload the host system, many terminal 
  262.  
  263. interface boards programmatically handle user input-output in lines.  Thus, 
  264.  
  265. before  any input is received by the host,  a whole line must  be  entered.  
  266.  
  267. Naturally,   the   characters   are  echoed  by  the   terminal   interface 
  268.  
  269. hardware/firmware,  and only limited line editing is permitted.  On output, 
  270.  
  271. a  whole  line is buffered up before transmission to  the  terminal.   This 
  272.  
  273. process  can be overcome by use of the 'raw' terminal mode (raw implies  no 
  274.  
  275. host  character  processing.)   In this mode,  the  program  is  completely 
  276.  
  277. responsible for input-output.  This mode is much more expensive in terms of 
  278.  
  279. input-output  cost,  since the host must handle an interrupt for each input 
  280.  
  281. character  and  perform  an  output request  for  each  printed  character.  
  282.  
  283. However,  as I mentioned in the previous column, this is the only way for a 
  284.  
  285. program  to get full control of what is entered and appears on the  display 
  286.  
  287. device.
  288.  
  289.     With the introduction of C to microcomputers, compiler implementors 
  290.  
  291. often based the behavior of the runtime libraries on their Unix experiences 
  292.  
  293. rather  than  on The C Programming Language.   Thus,  whole lines are  pre-
  294.  
  295. buffered  by  typical  C runtime libraries before  a  single  character  is 
  296.  
  297. received  by  getc().   Conversely,  a whole line of output  is  internally 
  298.  
  299. buffered before it is printed on the display.   Thus, the runtime libraries 
  300.  
  301. of  microcomputer C compilers often emulate the terminal hardware found  on 
  302.  
  303. real  Unix systems.   However,  this is not what putc() and getc() are sup-
  304.  
  305. posed  to do.   In the truest sense,  raw mode is the fundamental  terminal 
  306.  
  307. mode.   These  functions  should really work on a  character  by  character 
  308.  
  309. basis.   C libraries should permit selection between the 'raw' and 'cooked' 
  310.  
  311. modes (and echo,  no-echo) and thus permit input-output flexibility without 
  312.  
  313. resorting to assembly language routines.  
  314.  
  315.     One  C compiler which correctly handles the low-level  input-output 
  316.  
  317. is the Q/C compiler from The  Code Works.   For example,  single characters 
  318.  
  319. are only required when a getchar() call is made.   However, it doesn't seem 
  320.  
  321. possible to turn off the echo.   Nevertheless,  this can be effected  under 
  322.  
  323. Q/C,  since  The Code Works is kind enough to provide runtime and  compiler 
  324.  
  325. source code. 
  326.  
  327.                                Link Formats
  328.  
  329.     In  the October,  1983,  column I discussed incompatibility between 
  330.  
  331. link formats.  Readers had quite a bit to say about this and their comments 
  332.  
  333. are summarized here.
  334.  
  335.     Guy Scharf of Mountain View, California, writes:
  336.  
  337.     "I  find the incompatibility of linkage editor formats to be a real 
  338. problem.   For example, I want to use Digital Research's Access Manager and 
  339. Display Manager 86 with C.   I would prefer CI-86 (because I am used to it) 
  340. but  have  to  switch  to DRI's C because  of  the  link  format.   Another 
  341. compiler to learn and idiosynchracies to surmount."
  342.  
  343.     He concludes:
  344.  
  345.     "I'm not sure what to do about this problem (except complain).
  346.  
  347.     David D. Clark of State College, Pennsylvania, writes:
  348.  
  349.     "The  big problem isn't really the format of linkable files.   Even 
  350. compilers  that use Microsoft's M80 and L80 will not allow linkage to  code 
  351. produced  by  different compilers.   The function  calling  protocols  vary 
  352. tremendously  from  compiler  to  compiler.   BDS C  and  Q/C  have  fairly 
  353. straightforward function calling protocols.  Eco-C,  on the other hand, has 
  354. a  tortuous function calling sequence.   And even though Q/C and Eco-C  use 
  355. the Microsoft assembler and linker, the code files produced by them are not 
  356. compatible." 
  357.  
  358.     The  problem that Mr.  Clark mentions is also present in  the  8086 
  359.  
  360. (MS-DOS,  CP/M-86)  world.   Code from different compilers cannot be  mixed 
  361.  
  362. because:
  363.  
  364.         1. each requires its own main function
  365.         2. a wide variety of link formats exist
  366.         3. calling conventions differ between compilers.
  367.  
  368. The  first two points are essentially insurmountable problems from the  end 
  369.  
  370. user's point of view.   However,  the third point can be overcome by adding 
  371.  
  372. dummy routines to convert calling conventions.
  373.  
  374.     Mr.  Clark makes some additional points concerning the deficiencies 
  375.  
  376. of  the  8080 Microsoft .REL (relocatable) format.   These are of  interest 
  377.  
  378. since many 8080 C compilers rely on this format.  His comments are included 
  379.  
  380. in Figure I. in tabular form. 
  381.  
  382.                ------------------FIGURE I.------------------    
  383.               Deficiencies in the Microsoft 8080 .REL format
  384.                            and related software
  385.  
  386.     1.    M80  and  DRI's  RMAC  assemblers  only  support  six  unique 
  387.         characters (all upper case).  This is awkward for many purposes.
  388.  
  389.         2.  While  the  .REL  format apparently will  handle  seven  unique 
  390.         characters, neither M80 nor RMAC support this.
  391.  
  392.         3.   Apparently the .REL format,  M80 and L80 were designed to work 
  393.         with  the  FORTRAN-80  compiler which permits  only  six  character 
  394.         symbols.   This is an old standard,  and does not reflect the needs 
  395.         of  today's compilers.   The absence of case sensitivity in symbols 
  396.         is especially limiting.
  397.  
  398.             -------------------END FIGURE I.------------------
  399.  
  400.  
  401.     It is obvious that an enhanced standard is necessary for the  CP/M-
  402.  
  403. 80  world.   Even  under MS-DOS,  where Microsoft has enhanced the  linkage 
  404.  
  405. editor format,  problems still exist.   These problems, as I perceive them, 
  406.  
  407. will be discussed next.
  408.  
  409.     Microsoft's MS-DOS linkage format supports long symbols (31  unique 
  410.  
  411. characters)  and has case sensitivity.   Thus,  it overcomes the objections 
  412.  
  413. that  Mr.  Clark  posed for the 8080 .REL  system.   However,  one  nagging 
  414.  
  415. problem  still exists.   This is the dichotomy between object  modules  and 
  416.  
  417. libraries.   Because  of this dichotomy,  the MS-DOS linker always includes 
  418.  
  419. the full contents of a .OBJ module during linking.   However, libraries are 
  420.  
  421. searched.   In  order to make a library efficient,  each function  must  be 
  422.  
  423. compiled into its own .OBJ file.  Each .OBJ file becomes a single sub-block 
  424.  
  425. in  the library;  all the functions of that sub-block file are included  at 
  426.  
  427. program  linkage.   If libraries and object modules were  equivalent,  this 
  428.  
  429. problem  would be overcome since the functions of an object module would be 
  430.  
  431. separable during linking.
  432.  
  433.                              Runtime Libraries
  434.  
  435.     Non-standard runtime libraries are a plague to  programmers.   They 
  436.  
  437. inhibit  portability,  and  introduce  bugs when  software  is  transported 
  438.  
  439. between different compilers.   Charles Brady of New South Wales, Australia, 
  440.  
  441. writes:
  442.  
  443.     "An enormous contribution to standardization of C programs would be 
  444. the publication of a standard I/O library for BDS C,  with, if necessary, a 
  445. modified   runtime  package.    The  very  fast  and  efficient   compiler, 
  446. particularly  with  the symbolic debugger tool,  provides a  very  inviting 
  447. environment  for software development.   It is a great pity that this means 
  448. abundant non-standard C.  As there is no inherent reason why this should be 
  449. the case ...  someone should be able to ...  produce a Unix compatible  I/O 
  450. library."
  451.  
  452.     This  point is especially well-taken in view of the large amount of 
  453.  
  454. BDS  C  software  available through the C User's  Group  of  Yates  Center, 
  455.  
  456. Kansas.  
  457.  
  458.     In  the  case  of  the runtime library itself,  there  is  a  clear 
  459.  
  460. standard.  This standard is spelled out in The C Programming Language.  All 
  461.  
  462. compilers  have  to  do  is support a  proper  subset  appropriate  to  the 
  463.  
  464. environment in which they work.
  465.  
  466.                                 Conclusion
  467.  
  468.     In  this column,  I have included the follow-up discussions on Unix 
  469.  
  470. and  on link formats/runtime libraries.   The nature of the discussion  has 
  471.  
  472. been  mainly  of  a  critical  nature.   This  is  not  intended  to  be  a 
  473.  
  474. condemnation of the systems, but only an impetus for readers to suggest new 
  475.  
  476. ideas to improve what we already have.   Unix is a worthwhile standard  and 
  477.  
  478. should  be supported.   C is a valuable tool,  but can be  improved.   This 
  479.  
  480. column  is a forum in which we can discuss,  develop and nurture new  ideas 
  481.  
  482. about C and Unix.
  483.  
  484.