home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 137_01 / apr84col.ddj < prev    next >
Encoding:
Text File  |  1979-12-31  |  18.2 KB  |  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.  
  17.  
  18. perceived  deficiencies in the Unix operating system.   Their comments  are 
  19.  
  20.  
  21.  
  22. included here in part.
  23.  
  24.     The  follow-up  discussion  on runtime libraries  and  link  format 
  25.  
  26.  
  27.  
  28. incompatibilities are also presented here.
  29.  
  30.     It  was also my intention to discuss two C compilers which  support 
  31.  
  32.  
  33.  
  34. the  large memory  concept on the 8086.   One of the compilers has not  yet 
  35.  
  36.  
  37.  
  38. been  received,  so this comparative review will have to be included  in  a 
  39.  
  40.  
  41.  
  42. future column.
  43.  
  44.     I have received several more letters concerning C layout standards.  
  45.  
  46.  
  47.  
  48. While  we  don't  have room to include their  comments  at  present,  their 
  49.  
  50.  
  51.  
  52. comments will undoubtedly lead to several columns concerning related topics 
  53.  
  54.  
  55.  
  56. of interest.  
  57.  
  58.                             Comments about Unix
  59.  
  60.     In the December column,  I mentioned several aspects of  Unix which 
  61.  
  62.  
  63.  
  64. I believe constitute weaknesses.   Tony LiCausi of Canoga Park, California, 
  65.  
  66.  
  67.  
  68. sent me a letter with his dissenting opinions.  He begins by remarking:
  69.  
  70.     "Unix was designed for the programming environment, for use by folk 
  71.  
  72. already  familiar with computers.   Unnecessary I/O slows down a  program's 
  73.  
  74. performance and hence should be eliminated.   Thankfully verbosity is often 
  75.  
  76. eliminated,  in Unix,  as the default option.  However many of the programs 
  77.  
  78. do  have  command line switches to increase the progress reporting  of  the 
  79.  
  80. program."
  81.  
  82.     Unix  was  designed to circumvent the flaws of  existing  operating 
  83.  
  84.  
  85.  
  86. systems. Under Unix, modular programs are coupled via pipelines to create a 
  87.  
  88.  
  89.  
  90. convenient   working   environment   and  reduce  repetition   of   effort.  
  91.  
  92.  
  93.  
  94. Furthermore,  Unix  offers unequalled portability between large  and  small 
  95.  
  96.  
  97.  
  98. computer  systems.   Since  it  is successful  in  these  respects,  Unix's 
  99.  
  100.  
  101.  
  102. popularity  is growing.   Hence,  more and more computer users are  gaining 
  103.  
  104.  
  105.  
  106. access  to machines which use Unix.   Many of these users are familiar with 
  107.  
  108.  
  109.  
  110. computers  and programming while others are novices to both  computing  and 
  111.  
  112.  
  113.  
  114. Unix.  
  115.  
  116.     Let's  assume that a user is well-versed in programming but is  new 
  117.  
  118.  
  119.  
  120. to  Unix.   According  to Mr.  LiCausi,  this user belongs to the group  of 
  121.  
  122.  
  123.  
  124. people  for  whom  Unix was designed.   I'll assume that the  user  has  an 
  125.  
  126.  
  127.  
  128. application  in mind,  since the average user won't be writing programs  as 
  129.  
  130.  
  131.  
  132. ends unto themselves.  To succeed in implementing his application, the user 
  133.  
  134.  
  135.  
  136. will have to learn about various aspects of Unix,  including various  shell 
  137.  
  138.  
  139.  
  140. commands, system calls, and runtime libraries.  However, I submit that this 
  141.  
  142.  
  143.  
  144. type  of user will be slowed down significantly by overall poor quality  of 
  145.  
  146.  
  147.  
  148. the Unix documentation.  Since examples in the Unix documents are typically 
  149.  
  150.  
  151.  
  152. both terse and highly complicated, the typical user could spend an enormous 
  153.  
  154.  
  155.  
  156. amount of time circumventing a single snag.  
  157.  
  158.     Imagine  linking  the mathematical function library as part of a  C 
  159.  
  160.  
  161.  
  162. compilation.  Two seemingly possible ways for doing this are:
  163.  
  164.         cc -o test test.c -lm
  165.  
  166. or
  167.  
  168.         cc -lm -o test test.c
  169.  
  170. It  turns out that the former method is correct while that latter  produces 
  171.  
  172.  
  173.  
  174. undefined  function  error messages at  the  linker  stage.   However,  the 
  175.  
  176.  
  177.  
  178. documentation  does not indicate that the '-lm' must be near the end of the 
  179.  
  180.  
  181.  
  182. line.  
  183.  
  184.     Our  hypothetical  user  will also be slowed down  by  the  cryptic 
  185.  
  186.  
  187.  
  188. nature  of error messages.   It is true that the more  sophisticated  users 
  189.  
  190.  
  191.  
  192. require  little or no prompting,  and only gentle nudges when they make  an 
  193.  
  194.  
  195.  
  196. incorrect  entry,  but the vast majority of users probably don't belong  to 
  197.  
  198.  
  199.  
  200. this category.
  201.  
  202.  
  203.     Finally,  the  user  will  be slowed down by inexplicable  and  un-
  204.  
  205.  
  206.  
  207. documented bugs in systems such as troff and eqn which I mentioned  before.   
  208.  
  209.  
  210.  
  211. Furthermore,  circumventing bugs requires highly specific knowledge.  Also, 
  212.  
  213.  
  214.  
  215. the  solutions,  even if available,  may not be widely known.   On the Unix 
  216.  
  217.  
  218.  
  219. machine I use,  only a small group of people are aware of the procedure for 
  220.  
  221.  
  222.  
  223. avoiding some common, but annoying, bugs in eqn. 
  224.  
  225.     Mr. LiCausi makes a very valid point concerning this:
  226.  
  227.     "Software  bugs are not acceptable in any form at any  time.   Unix 
  228.  
  229. from  Bell Labs is sold as unsupported software.   Their attitude is,  'OK, 
  230.  
  231. we'll  sell it to you but,  we don't want to here from you.'  There  is  no 
  232.  
  233. mechanism  to  report or correct bugs at the source.   Source code  is  not 
  234.  
  235. typically  available to the average user.   Source code is guarded on  Unix 
  236.  
  237. like gold;  just like any other commercial software.  Having done debugging 
  238.  
  239. of  the f77 compiler on one system,  access to other software (for  example 
  240.  
  241. and integration) was severely limited."
  242.  
  243.     Thus,  while Mr. LiCausi contends that Unix was designed for people 
  244.  
  245.  
  246.  
  247. with programming experience, he sets his standard for 'unnecessary I/O' and 
  248.  
  249.  
  250.  
  251. 'program  performance' based on the most sophisticated level of Unix  user.  
  252.  
  253.  
  254.  
  255. Furthermore, it is still not clear to me why the sophisticated users should 
  256.  
  257.  
  258.  
  259. be more willing to stand for poor quality documentation and user-unfriendly 
  260.  
  261.  
  262.  
  263. software  than every-day users.   Finally,  it is not at all apparent to me 
  264.  
  265.  
  266.  
  267. from  practical  experience  that 'many' of  the  standard  shell  commands 
  268.  
  269.  
  270.  
  271. support extended progress reporting. 
  272.  
  273.     Mr. LiCausi goes on to state:
  274.  
  275.     "The secret society of Unix is partially the result of the paranoia 
  276.  
  277. of  'unauthorized access.'  The remainder is due to the lack of  commercial 
  278.  
  279. incentive.   The  incentive has obviously increased as can be evidenced  by 
  280.  
  281. the proliferation of books and articles on Unix anc C."
  282.  
  283.     I  stated in my previous column that some users perceive Unix as  a 
  284.  
  285.  
  286.  
  287. secret society.  This is the case because they cannot grasp certain aspects 
  288.  
  289.  
  290.  
  291. of  its  operation  based on the written and on-line  documentation  alone.  
  292.  
  293.  
  294.  
  295. Only through initiated members can the knowledge (and undocumented  tricks, 
  296.  
  297.  
  298.  
  299. patches  etc.)  be obtained.   Thus people feel left  out.   Other  popular 
  300.  
  301.  
  302.  
  303. operating  systems do not have the same aura as Unix.   For  example,  CP/M 
  304.  
  305.  
  306.  
  307. users  are  not  considered a 'secret society' even though  CP/M  has  non-
  308.  
  309.  
  310.  
  311. trivial  aspects.   Furthermore,  minicomputer  operating systems  such  as 
  312.  
  313.  
  314.  
  315. VAX/VMS  (DEC) and AOS/VS (Data General) don't have the mysterious  quality 
  316.  
  317.  
  318.  
  319. of  Unix.   That's because they have much more documentation to explain the 
  320.  
  321.  
  322.  
  323. nitty-gritty of using the system.  
  324.  
  325.     Mr. LiCausi finishes by stating:
  326.  
  327.     "Unix  is not user-unfriendly.   Admittedly it is beginner hostile.  
  328.  
  329. Changes will be required to adopt Unix en masse,  ie for the micro,  but  I 
  330.  
  331. hope that it does not spell the end of 'silent' software."
  332.  
  333.     My final counter-remark is that most users never become sufficently 
  334.  
  335.  
  336.  
  337. sophisticated  in enough diverse aspects of Unix to escape the  feeling  of 
  338.  
  339.  
  340.  
  341. user-hostility.   I personally run into difficulties, even though I've used 
  342.  
  343.  
  344.  
  345. Unix for almost four years.  As soon as I use aspects of Unix which are not 
  346.  
  347.  
  348.  
  349. part of my daily routine, 'gottchas' appear.
  350.  
  351.                            Other Points of View
  352.  
  353.  
  354.     H.T. Gordon sent in a letter concerning Unix.  He writes:
  355.  
  356.     "It  was a pleasure to read the Skjellum critique of [Unix] in  DDJ 
  357.  
  358. #86.   Since  C/Unix  is becoming the sacred cow of the computer  Brahmins, 
  359.  
  360. few have the courage to point out its flaws.  It was designed by one of the 
  361.  
  362. elite,  for elite users.  To them it's concise and elegant, even 'obvious.'  
  363.  
  364. Only  rarely  is any explanation needed.   If it is,  a terse one will  do.  
  365.  
  366. Prophets inspired by the high gods cannot waste their time spelling  things 
  367.  
  368. out for mere morals in words of one syllable."
  369.  
  370.     I  don't  think that the state of C/Unix is as bad  as  Mr.  Gordon 
  371.  
  372.  
  373.  
  374. suggests.   While there are problems,  I think that Unix has many strengths 
  375.  
  376.  
  377.  
  378. and these strengths will be the basis for future operating systems.   It is 
  379.  
  380.  
  381.  
  382. the  purpose  of this column to discuss strengths and weaknesses of  C  and 
  383.  
  384.  
  385.  
  386. Unix  and  to propose solutions as well as to point out  the  problems.   I 
  387.  
  388.  
  389.  
  390. encourage  readers  to  pose  solutions to these and  other  problems  they 
  391.  
  392.  
  393.  
  394. perceive.
  395.                         Low level Input-Output in C
  396.  
  397.     Patrick Cawood of Los Angeles writes:
  398.  
  399.     "I read with great interest your last article on tendencies in Unix 
  400.  
  401. to produce poor operator interaction programs.   I seem to have met some of 
  402.  
  403. the same in C."
  404.  
  405.     "In order to provide a secure operator interface, one does not echo 
  406.  
  407. a keyboard character to the screen until it has been examined and  approved 
  408.  
  409. by the program. But getch() function automatically echoes--even line feeds, 
  410.  
  411. up arrows,  etc.!!   Function putch() provides an automatic line feed after 
  412.  
  413. printing on the screen!!
  414.  
  415.     He goes on to state:
  416.  
  417.     "I  simply cannot believe that anyone would wittingly design  these 
  418.  
  419. functions as they are,  or not provide any alternative hardware interfaces.  
  420.  
  421. Especially  considering   some of the tasks I've heard were written  in  C.  
  422.  
  423. But  perhaps these people writing serious software were all forced to write 
  424.  
  425. their own hardware interfaces."
  426.  
  427.     The problem which Mr.  Cawood is referring to exists in a number of 
  428.  
  429.  
  430.  
  431. non-Unix C compilers.   To begin with, let's review the problem in the Unix 
  432.  
  433.  
  434.  
  435. environment.   Under  Unix,  putc() and getc() acquire and return a  single 
  436.  
  437.  
  438.  
  439. character respectively.  However, to offload the host system, many terminal 
  440.  
  441.  
  442.  
  443. interface boards programmatically handle user input-output in lines.  Thus, 
  444.  
  445.  
  446.  
  447. before  any input is received by the host,  a whole line must  be  entered.  
  448.  
  449.  
  450.  
  451. Naturally,   the   characters   are  echoed  by  the   terminal   interface 
  452.  
  453.  
  454.  
  455. hardware/firmware,  and only limited line editing is permitted.  On output, 
  456.  
  457.  
  458.  
  459. a  whole  line is buffered up before transmission to  the  terminal.   This 
  460.  
  461.  
  462.  
  463. process  can be overcome by use of the 'raw' terminal mode (raw implies  no 
  464.  
  465.  
  466.  
  467. host  character  processing.)   In this mode,  the  program  is  completely 
  468.  
  469.  
  470.  
  471. responsible for input-output.  This mode is much more expensive in terms of 
  472.  
  473.  
  474.  
  475. input-output  cost,  since the host must handle an interrupt for each input 
  476.  
  477.  
  478.  
  479. character  and  perform  an  output request  for  each  printed  character.  
  480.  
  481.  
  482.  
  483. However,  as I mentioned in the previous column, this is the only way for a 
  484.  
  485.  
  486.  
  487. program  to get full control of what is entered and appears on the  display 
  488.  
  489.  
  490.  
  491. device.
  492.  
  493.     With the introduction of C to microcomputers, compiler implementors 
  494.  
  495.  
  496.  
  497. often based the behavior of the runtime libraries on their Unix experiences 
  498.  
  499.  
  500.  
  501. rather  than  on The C Programming Language.   Thus,  whole lines are  pre-
  502.  
  503.  
  504.  
  505. buffered  by  typical  C runtime libraries before  a  single  character  is 
  506.  
  507.  
  508.  
  509. received  by  getc().   Conversely,  a whole line of output  is  internally 
  510.  
  511.  
  512.  
  513. buffered before it is printed on the display.   Thus, the runtime libraries 
  514.  
  515.  
  516.  
  517. of  microcomputer C compilers often emulate the terminal hardware found  on 
  518.  
  519.  
  520.  
  521. real  Unix systems.   However,  this is not what putc() and getc() are sup-
  522.  
  523.  
  524.  
  525. posed  to do.   In the truest sense,  raw mode is the fundamental  terminal 
  526.  
  527.  
  528.  
  529. mode.   These  functions  should really work on a  character  by  character 
  530.  
  531.  
  532.  
  533. basis.   C libraries should permit selection between the 'raw' and 'cooked' 
  534.  
  535.  
  536.  
  537. modes (and echo,  no-echo) and thus permit input-output flexibility without 
  538.  
  539.  
  540.  
  541. resorting to assembly language routines.  
  542.  
  543.     One  C compiler which correctly handles the low-level  input-output 
  544.  
  545.  
  546.  
  547. is the Q/C compiler from The  Code Works.   For example,  single characters 
  548.  
  549.  
  550.  
  551. are only required when a getchar() call is made.   However, it doesn't seem 
  552.  
  553.  
  554.  
  555. possible to turn off the echo.   Nevertheless,  this can be effected  under 
  556.  
  557.  
  558.  
  559. Q/C,  since  The Code Works is kind enough to provide runtime and  compiler 
  560.  
  561.  
  562.  
  563. source code. 
  564.  
  565.                                Link Formats
  566.  
  567.     In  the October,  1983,  column I discussed incompatibility between 
  568.  
  569.  
  570.  
  571. link formats.  Readers had quite a bit to say about this and their comments 
  572.  
  573.  
  574.  
  575. are summarized here.
  576.  
  577.     Guy Scharf of Mountain View, California, writes:
  578.  
  579.     "I  find the incompatibility of linkage editor formats to be a real 
  580.  
  581. problem.   For example, I want to use Digital Research's Access Manager and 
  582.  
  583. Display Manager 86 with C.   I would prefer CI-86 (because I am used to it) 
  584.  
  585. but  have  to  switch  to DRI's C because  of  the  link  format.   Another 
  586.  
  587. compiler to learn and idiosynchracies to surmount."
  588.  
  589.     He concludes:
  590.  
  591.     "I'm not sure what to do about this problem (except complain).
  592.  
  593.     David D. Clark of State College, Pennsylvania, writes:
  594.  
  595.     "The  big problem isn't really the format of linkable files.   Even 
  596.  
  597. compilers  that use Microsoft's M80 and L80 will not allow linkage to  code 
  598.  
  599. produced  by  different compilers.   The function  calling  protocols  vary 
  600.  
  601. tremendously  from  compiler  to  compiler.   BDS C  and  Q/C  have  fairly 
  602.  
  603. straightforward function calling protocols.  Eco-C,  on the other hand, has 
  604.  
  605. a  tortuous function calling sequence.   And even though Q/C and Eco-C  use 
  606.  
  607. the Microsoft assembler and linker, the code files produced by them are not 
  608.  
  609. compatible." 
  610.  
  611.     The  problem that Mr.  Clark mentions is also present in  the  8086 
  612.  
  613.  
  614.  
  615. (MS-DOS,  CP/M-86)  world.   Code from different compilers cannot be  mixed 
  616.  
  617.  
  618.  
  619. because:
  620.  
  621.         1. each requires its own main function
  622.         2. a wide variety of link formats exist
  623.         3. calling conventions differ between compilers.
  624.  
  625. The  first two points are essentially insurmountable problems from the  end 
  626.  
  627.  
  628.  
  629. user's point of view.   However,  the third point can be overcome by adding 
  630.  
  631.  
  632.  
  633. dummy routines to convert calling conventions.
  634.  
  635.     Mr.  Clark makes some additional points concerning the deficiencies 
  636.  
  637.  
  638.  
  639. of  the  8080 Microsoft .REL (relocatable) format.   These are of  interest 
  640.  
  641.  
  642.  
  643. since many 8080 C compilers rely on this format.  His comments are included 
  644.  
  645.  
  646.  
  647. in Figure I. in tabular form. 
  648.  
  649.                ------------------FIGURE I.------------------    
  650.               Deficiencies in the Microsoft 8080 .REL format
  651.                            and related software
  652.  
  653.     1.    M80  and  DRI's  RMAC  assemblers  only  support  six  unique 
  654.  
  655.         characters (all upper case).  This is awkward for many purposes.
  656.  
  657.         2.  While  the  .REL  format apparently will  handle  seven  unique 
  658.  
  659.         characters, neither M80 nor RMAC support this.
  660.  
  661.         3.   Apparently the .REL format,  M80 and L80 were designed to work 
  662.  
  663.         with  the  FORTRAN-80  compiler which permits  only  six  character 
  664.  
  665.         symbols.   This is an old standard,  and does not reflect the needs 
  666.  
  667.         of  today's compilers.   The absence of case sensitivity in symbols 
  668.  
  669.         is especially limiting.
  670.  
  671.             -------------------END FIGURE I.------------------
  672.  
  673.  
  674.     It is obvious that an enhanced standard is necessary for the  CP/M-
  675.  
  676.  
  677.  
  678. 80  world.   Even  under MS-DOS,  where Microsoft has enhanced the  linkage 
  679.  
  680.  
  681.  
  682. editor format,  problems still exist.   These problems, as I perceive them, 
  683.  
  684.  
  685.  
  686. will be discussed next.
  687.  
  688.     Microsoft's MS-DOS linkage format supports long symbols (31  unique 
  689.  
  690.  
  691.  
  692. characters)  and has case sensitivity.   Thus,  it overcomes the objections 
  693.  
  694.  
  695.  
  696. that  Mr.  Clark  posed for the 8080 .REL  system.   However,  one  nagging 
  697.  
  698.  
  699.  
  700. problem  still exists.   This is the dichotomy between object  modules  and 
  701.  
  702.  
  703.  
  704. libraries.   Because  of this dichotomy,  the MS-DOS linker always includes 
  705.  
  706.  
  707.  
  708. the full contents of a .OBJ module during linking.   However, libraries are 
  709.  
  710.  
  711.  
  712. searched.   In  order to make a library efficient,  each function  must  be 
  713.  
  714.  
  715.  
  716. compiled into its own .OBJ file.  Each .OBJ file becomes a single sub-block 
  717.  
  718.  
  719.  
  720. in  the library;  all the functions of that sub-block file are included  at 
  721.  
  722.  
  723.  
  724. program  linkage.   If libraries and object modules were  equivalent,  this 
  725.  
  726.  
  727.  
  728. problem  would be overcome since the functions of an object module would be 
  729.  
  730.  
  731.  
  732. separable during linking.
  733.  
  734.                              Runtime Libraries
  735.  
  736.     Non-standard runtime libraries are a plague to  programmers.   They 
  737.  
  738.  
  739.  
  740. inhibit  portability,  and  introduce  bugs when  software  is  transported 
  741.  
  742.  
  743.  
  744. between different compilers.   Charles Brady of New South Wales, Australia, 
  745.  
  746.  
  747.  
  748. writes:
  749.  
  750.     "An enormous contribution to standardization of C programs would be 
  751.  
  752. the publication of a standard I/O library for BDS C,  with, if necessary, a 
  753.  
  754. modified   runtime  package.    The  very  fast  and  efficient   compiler, 
  755.  
  756. particularly  with  the symbolic debugger tool,  provides a  very  inviting 
  757.  
  758. environment  for software development.   It is a great pity that this means 
  759.  
  760. abundant non-standard C.  As there is no inherent reason why this should be 
  761.  
  762. the case ...  someone should be able to ...  produce a Unix compatible  I/O 
  763.  
  764. library."
  765.  
  766.     This  point is especially well-taken in view of the large amount of 
  767.  
  768.  
  769.  
  770. BDS  C  software  available through the C User's  Group  of  Yates  Center, 
  771.  
  772.  
  773.  
  774. Kansas.  
  775.  
  776.     In  the  case  of  the runtime library itself,  there  is  a  clear 
  777.  
  778.  
  779.  
  780. standard.  This standard is spelled out in The C Programming Language.  All 
  781.  
  782.  
  783.  
  784. compilers  have  to  do  is support a  proper  subset  appropriate  to  the 
  785.  
  786.  
  787.  
  788. environment in which they work.
  789.  
  790.                                 Conclusion
  791.  
  792.     In  this column,  I have included the follow-up discussions on Unix 
  793.  
  794.  
  795.  
  796. and  on link formats/runtime libraries.   The nature of the discussion  has 
  797.  
  798.  
  799.  
  800. been  mainly  of  a  critical  nature.   This  is  not  intended  to  be  a 
  801.  
  802.  
  803.  
  804. condemnation of the systems, but only an impetus for readers to suggest new 
  805.  
  806.  
  807.  
  808. ideas to improve what we already have.   Unix is a worthwhile standard  and 
  809.  
  810.  
  811.  
  812. should  be supported.   C is a valuable tool,  but can be  improved.   This 
  813.  
  814.  
  815.  
  816. column  is a forum in which we can discuss,  develop and nurture new  ideas 
  817.  
  818.  
  819.  
  820. about C and Unix.
  821.  
  822.  
  823.