home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 137_01 / aug84col.ddj < prev    next >
Encoding:
Text File  |  1979-12-31  |  16.7 KB  |  464 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 August, 1984 DDJ. 
  10.  
  11.  
  12.                                Introduction
  13.  
  14.     In  this  column,  we'll discuss some of the feedback  received  in 
  15.  
  16.  
  17.  
  18. response to previous columns, as well as some miscellaneous remarks.  
  19.  
  20.                          uucp (Unix to Unix Copy)
  21.  
  22.     Mike  Meyers  of  Norman,  OK,  suggested that I  publish  my  uucp 
  23.  
  24.  
  25.  
  26. address.   Via  this address,  users on other Unix systems can send me mail 
  27.  
  28.  
  29.  
  30. electronically by using the standard Unix mail command.   A uucp address is 
  31.  
  32.  
  33.  
  34. specified   relative   to   a   well-known   site.    Thus,   the   address 
  35.  
  36.  
  37.  
  38. "ucbvax|cithep|tony"  should allow most users to reach me.   If  your  site 
  39.  
  40.  
  41.  
  42. cannot communicate with ucbvax (UC Berkeley) directly, more site names will 
  43.  
  44.  
  45.  
  46. have  to be prepended onto this address,  and onto to those listed below as 
  47.  
  48.  
  49.  
  50. well.   On  the  other  hand,  if  your site can  communicate  with  cithep 
  51.  
  52.  
  53.  
  54. (Caltech High Energy Physics) directly, the ucbvax prefix may be omitted.
  55.  
  56.     If  a  continuing electronic dialog develops,  I will  occasionally 
  57.  
  58.  
  59.  
  60. publish   the  uucp  addresses  of  those  involved  so  that  others   may 
  61.  
  62.  
  63.  
  64. participate.   At  the moment,  the following users are participating in  a 
  65.  
  66.  
  67.  
  68. discussion about Unix:
  69.  
  70.         ucbvax|mtxinu|ea|jab   (Jeff A. Bowles)
  71.         ucbvax|cithep|yekta    (Yekta Gursel)
  72.         ucbvax|mtxinu|ea|emjej (James Jones)    
  73.         ucbvax|mtxinu|ea|mwm   (Mike Meyers)
  74.  
  75. Interesting  remarks will be included in future columns for the benefit  of 
  76.  
  77.  
  78.  
  79. those readers who cannot access the electronic mail.
  80.  
  81.                                C Users Group
  82.  
  83.     Phillip  K.  Landis  of Satellite Beach,  FL,  inquired  about  the 
  84.  
  85.  
  86.  
  87. address of the C Users Group of Yates Center,  KS, which I mentioned in the 
  88.  
  89.  
  90.  
  91. April column.  Their address and telephone are as follows:
  92.  
  93.         C Users Group
  94.         105 E. Rutledge
  95.         Yates Center, KS  66783
  96.         (316) 625-3554
  97.  
  98. This  particular  group has 34 volumes of C programs and offers them  in  a 
  99.  
  100.  
  101.  
  102. variety  of  disk formats (only for microcomputers).   If there  are  other 
  103.  
  104.  
  105.  
  106. public-domain C repositories,  I would like to print their addresses  also. 
  107.  
  108.  
  109.  
  110. If you know of one, please forward me their address. 
  111.  
  112.                               Public Domain C
  113.  
  114.     Robert E. Fiorini of Albany, NY, writes: 
  115.  
  116.     "I'm a new 'C' user trying to find an inexpensive (possibly public-
  117.  
  118. domain) 'C' compiler (with source code...if possible).  My own efforts have 
  119.  
  120. been  fruitless.   I'm hoping that you or one of your readers may know of a 
  121.  
  122. source  where  I  can find such a compiler.   If you can  help  me  in  any 
  123.  
  124. way...please HELP !!...It's funny,  the only thing holding me back from the 
  125.  
  126. world of C is the C)ompiler itself.  "
  127.  
  128.     Rod  Cain's Small C is available through the C User's group  listed 
  129.  
  130.  
  131.  
  132. above.   An enhanced version (not public domain) for 8080/Z80 CP/M  systems 
  133.  
  134.  
  135.  
  136. is available (with source code) from The Code Works of Goleta,  CA.  (Their 
  137.  
  138.  
  139.  
  140. address  can  be found in any number of DDJ back issues.)  This  particular 
  141.  
  142.  
  143.  
  144. compiler  (Q/C)  is  a  serious subset  implementation  and  includes  full 
  145.  
  146.  
  147.  
  148. compiler  source  for $95.00.   An IBM version of this  product  should  be 
  149.  
  150.  
  151.  
  152. available  later this year and would be well-worth the investment if priced 
  153.  
  154.  
  155.  
  156. comparably to the CP/M version.
  157.  
  158.                        Comments about C input-output
  159.  
  160.     Mike Meyers writes:
  161.  
  162.     "What  you haven't seemed to realize is that almost every  flaw  in 
  163.  
  164. Unix  also  appears in C.   C is terse,  doesn't protect the user,  and  is 
  165.  
  166. poorly  documented.   The  only documentation for C is K&R  [Kernighan  and 
  167.  
  168. Ritchie],  which may be well-written,  but is vague and inconsistent on all 
  169.  
  170. the points you turn to for when you start implementing the language on  new 
  171.  
  172. machines.   To  make matters worse,  nobody (and I do mean nobody) sells  a 
  173.  
  174. compiler that conforms to K&R,  not even AT&T.   I don't think anybody ever 
  175.  
  176. has,  in any case.  AT&T distributes a version of pcc [portable C compiler] 
  177.  
  178. that  met  K&R  internally,  but I think that by the time it  was  released 
  179.  
  180. externally, C had grown past K&R."
  181.  
  182.     Gerald I. Evenden of N. Falmouth, MA responded about C input-output 
  183.  
  184.  
  185.  
  186. as follows, with quite a different point of view:
  187.  
  188.     "I  was very disturbed with a basic concept about the C programming 
  189.  
  190. language that you kept implying in your column in the April  issue.   First 
  191.  
  192. of all I suggest that you carefully read the beginning paragraph of chapter 
  193.  
  194. 7 of Kernighan and Ritchie's book: "The C Programming Language."  It begins 
  195.  
  196. with  'Input and Output are not part of the C Language,  ...'  What remains 
  197.  
  198. is  a  description of i/o procedures contained in a standard  UNIX  library 
  199.  
  200. which will take care of most filter type of functional operations.   I have 
  201.  
  202. generally  found  them to be quite adequate for  most  programming  efforts 
  203.  
  204. involving stream data and simple question-answer type of console i/o."
  205.  
  206.     I would like to state that I am completely aware of the distinction 
  207.  
  208.  
  209.  
  210. between  the C language definition and the standard  input-output  library.  
  211.  
  212.  
  213.  
  214. In teaching students how to program in C, this is one of the first points I 
  215.  
  216.  
  217.  
  218. emphasize:  C is a language which gives no special favoritism to a specific 
  219.  
  220.  
  221.  
  222. set of input-output routines.  One standard set does exist, and this is the 
  223.  
  224.  
  225.  
  226. Unix standard.   I consider this an essential feature of C, but I feel that 
  227.  
  228.  
  229.  
  230. a  discussion  of a real C compiler environment cannot always be  separated 
  231.  
  232.  
  233.  
  234. from  a  discussion of the support library which comes  with  it.   I  also 
  235.  
  236.  
  237.  
  238. maintain  that  the  Unix input-output library is more  than  adequate  for 
  239.  
  240.  
  241.  
  242. dealing  with stream operations.   Mr.  Evenden summarizes the  distinction 
  243.  
  244.  
  245.  
  246. between C and C input-output as follows:
  247.  
  248.     "The  beauty  of  C  is  that  it  doesn't  have  [a]  plethora  of 
  249.  
  250. specialized  built  in functions but rather provides the programmer with  a 
  251.  
  252. rich  facility  to  build tools required  for  his  own,  and  occasionally 
  253.  
  254. specialized,  needs.   Obviously,  we  shouldn't  have to redesign all  the 
  255.  
  256. wheels  needed,  so  most  suppliers of C compilers include  a  library  of 
  257.  
  258. functions  patterned  after the UNIX libraries.   But  remember,  there  is 
  259.  
  260. absolutely no requirement to use them if they don't fit your needs and they 
  261.  
  262. should only be viewed as a preliminary tool kit." 
  263.  
  264.     One  point that merits further exploration is that of  portability.  
  265.  
  266.  
  267.  
  268. While it is well and good to preach the separation of C and C input-output, 
  269.  
  270.  
  271.  
  272. only  software  which uses standard Unix input-output calls  (and  routines 
  273.  
  274.  
  275.  
  276. built  on  them)  have a prayer of being moved  readily  between  different 
  277.  
  278.  
  279.  
  280. machines or even between different compilers on the same machines.  
  281.  
  282.     Mr. Evenden continues: "I suspect that your problem with "getc" et. 
  283.  
  284. al. is related to screen editing and control which is a category of program 
  285.  
  286. that  doesn't fall into the "filter" class of function emphasized  by  UNIX 
  287.  
  288. (and  its libraries) and I certainly agree that these functions don't  work 
  289.  
  290. in  this  case...the astute programmer writes 'rawin()' and 'rawout(),'  to 
  291.  
  292. satisfy  those  needs.   There's nothing to prevent it  and  everything  to 
  293.  
  294. encourage  it...The  worst possible outcome of the problems posed  in  your 
  295.  
  296. article  is  to  even  remotely suggest rewriting the  current  stream  i/o 
  297.  
  298. functions.   Their current form is a de facto standard and a consistency of 
  299.  
  300. implementation is expected by most C programmers."
  301.  
  302.     I  really  don't  expect anyone to throw away the  existing  stream 
  303.  
  304.  
  305.  
  306. functions.   Not  only  would  this  be  unreasonable,  it  would  also  be 
  307.  
  308.  
  309.  
  310. undesirable.   However,  I do feel that clean raw input-output should be  a 
  311.  
  312.  
  313.  
  314. supported capability;  it needn't be reinvented each time a Unix programmer 
  315.  
  316.  
  317.  
  318. discovers   that  stream  input-output  is  inconvenient  for   interactive 
  319.  
  320.  
  321.  
  322. purposes.   In  discussing  a  similar worry expressed  by  Mr.  Meyers,  I 
  323.  
  324.  
  325.  
  326. summarized  my  argument by stating that interactive  programs  comprise  a 
  327.  
  328.  
  329.  
  330. large  fraction  of  those run by Unix users,  and that when  a  programmer 
  331.  
  332.  
  333.  
  334. writes  an  interactive program,  he doesn't usually want the  user  to  be 
  335.  
  336.  
  337.  
  338. treated like an input file.  
  339.  
  340.     Despite the extremely outspoken way Mr.  Evenden lectures me in his 
  341.  
  342.  
  343.  
  344. letter,  we  actually  agree in many respects.   However,  some  things  he 
  345.  
  346.  
  347.  
  348. brought up demand careful examination.  He states:
  349.  
  350.  
  351.     "The  principle  point of this complaint is that you  should  be  a 
  352.  
  353. little more careful of what you are talking about.   Writing about problems 
  354.  
  355. with  C i/o is impossible since C i/o doesn't exist.   However,  your  less 
  356.  
  357. experienced  readers will take your complaint to heart and decide that C is 
  358.  
  359. a useless language because Mr.  Skjellum,  et. al., don't like the optional 
  360.  
  361. i/o  library supplied with their compiler.   If you were more  positive  in 
  362.  
  363. your  approach  you  would  be  telling readers  how  to  write  their  own 
  364.  
  365. procedures to do specialized console i/o on UNIX,  CP/M, etc.. I've done it 
  366.  
  367. on  both CP/M and UNIX and found it to be a piece of cake in both cases and 
  368.  
  369. never gave the "getc" group a second thought when it was obvious that  they 
  370.  
  371. were not meant for the job at hand."
  372.  
  373.     The  comments I have made are based on several years of  experience 
  374.  
  375.  
  376.  
  377. with C under Unix,  CP/M, VMS etc.  One must come to grips with reality.  C 
  378.  
  379.  
  380.  
  381. input-output,  while optional,  is normally what users must utilize to deal 
  382.  
  383.  
  384.  
  385. with  a problem at hand;  consequently,  inexperienced users must lean more 
  386.  
  387.  
  388.  
  389. heavily on the standard library than experienced users.   It is  meaningful 
  390.  
  391.  
  392.  
  393. to  discuss  C input-output.   It does exist,  and  Mr.  Evenden  discusses 
  394.  
  395.  
  396.  
  397. several  points about it before stating that the topic is beyond the  realm 
  398.  
  399.  
  400.  
  401. of discussion.   Inexperienced users learn by reading dialog between others 
  402.  
  403.  
  404.  
  405. who  have  seen problems in their own work.  Censoring this information  to 
  406.  
  407.  
  408.  
  409. "protect"  such  users  from  disenchantment  with  C  is  an  unacceptable 
  410.  
  411.  
  412.  
  413. alternative.  
  414.  
  415.     We have not reached the computer millenium.  C and Unix as existing 
  416.  
  417.  
  418.  
  419. tools  have  flaws  and drawbacks.   Only through discussion  can  we  seek 
  420.  
  421.  
  422.  
  423. solutions,  and  create  better future systems.   The idea  of  restricting 
  424.  
  425.  
  426.  
  427. discussions  based  on semantic points seems to be contrary to  that  goal.  
  428.  
  429.  
  430.  
  431. Some  other writers have taken the approach that C and Unix are 'wonderful' 
  432.  
  433.  
  434.  
  435. tools and heap praise on them in review after review.   A certain group  of 
  436.  
  437.  
  438.  
  439. individual  feel highly insulted if this approach is not followed.   In  an 
  440.  
  441.  
  442.  
  443. evolving  field,  it  makes  sense  to criticize as part  of  the  learning 
  444.  
  445.  
  446.  
  447. process. That is why I include Mr. Evenden's final remarks, because I think 
  448.  
  449.  
  450.  
  451. that  he  has drawn a counterproductive conclusion from  an  understandable 
  452.  
  453.  
  454.  
  455. point of view:
  456.  
  457.     "C  is  not  a perfect language but it certainly  beats  what's  in 
  458.  
  459. second  place.    Consequently,   my  enthusiasm  about  C  makes  me  very 
  460.  
  461. chauvinistic  about misplaced and invalid criticisms.   I have a couple  of 
  462.  
  463. minor complaints about some aspects of C but I bite my tongue when I  think 
  464.  
  465. about  the dark ages.   After several happy years with Algol in the 60's  I 
  466.  
  467. was  sentenced to over 10 long years of FORTRAN purgatory before being born 
  468.  
  469. again  with  C.   I  guard this language jealously and you  had  better  be 
  470.  
  471. careful  of what you write or I'll curse you to a task of debugging  10,000 
  472.  
  473. lines of BASIC code."
  474.  
  475.     I  hope that Mr.  Evenden will reconsider and send in his  comments 
  476.  
  477.  
  478.  
  479. about C so we can add them to the discussion.
  480.  
  481.                           BDS C Runtime solution
  482.  
  483.     Alex  Cameron of Malvern,  (Victoria,) Australia had the  following 
  484.  
  485.  
  486.  
  487. comments:
  488.  
  489.     "I  couldn't  help  responding to your notes  on  the  non-standard 
  490.  
  491. nature of some of BDS C's runtime routines (Dr.  Dobb's No.  90).  There is 
  492.  
  493. probably  little  doubt that most of us gladly  suffer  its  irregularities 
  494.  
  495. because  of  its  speed,  low price and because it is arguably one  of  the 
  496.  
  497. finest C compilers around - all this notwithstanding I still find the  non-
  498.  
  499. standard  buffered  file  functions,  such as fopen the  most  frustrating, 
  500.  
  501. simply because of the need to continually declare buffers."
  502.  
  503.     Listing I.  (stdlib3.c) is Mr.  Cameron's proposed solution to this 
  504.  
  505.  
  506.  
  507. problem under BDS C.
  508.  
  509. .pa
  510.  
  511.                      ---------- LISTING I. ----------
  512.  
  513. /*
  514. ** stdlib3.c -- standard I/O library
  515. **
  516. ** Copyright 1984  A. Cameron
  517. */
  518. #include "bdscio.h"
  519. /*
  520. **
  521. **    Standard fopen
  522. **
  523. **         return fd on success, NULL on error    
  524.  
  525. **
  526. */
  527.  
  528. sfopen(filename,mode)
  529. char *filename;
  530. char *mode;
  531. {
  532.     int fd;
  533.  
  534.     if (*mode == 'w')    /* write mode */
  535.     {
  536.         if (!(fd = alloc(BUFSIZ)))
  537.             return(NULL);
  538.         else
  539.         {
  540.             if (fcreat(filename,fd) == -1)
  541.             {
  542.                 free(fd);
  543.                 return(NULL);
  544.             }
  545.  
  546.             return(fd);
  547.         }
  548.  
  549.     }
  550.  
  551.     if (*mode == 'r')    /* read mode */
  552.     {
  553.         if (!(fd = alloc(BUFSIZ)))
  554.             return(NULL);
  555.         else
  556.         {
  557.             if (fopen(filename,fd) == -1)
  558.             {
  559.                 free(fd);
  560.                 return(NULL);
  561.             }
  562.  
  563.  
  564.             return(fd);
  565.         }
  566.     }
  567.  
  568.     if (*mode == 'a')    /* append mode */
  569.     {
  570.         if (!(fd = alloc(BUFSIZ)))
  571.             return(NULL);
  572.         else
  573.         {
  574.             if (fappend(filename,fd) == -1)
  575.             {
  576.                 free(fd);
  577.                 return(NULL);
  578.             }
  579.  
  580.             return(fd);
  581.  
  582.     }
  583.  
  584.     return(NULL);    /* failure */
  585.  
  586. }       
  587.  
  588. /*
  589. **
  590. **    Standard fclose
  591. **
  592. */
  593.  
  594. sfclose(fd)
  595. int fd;
  596. {
  597.     fputc(CPMEOF,fd);
  598.  
  599.     if (!(fclose(fd)))
  600.     {
  601.         free(fd);
  602.         return(NULL);
  603.     }
  604.  
  605.     return(ERROR);
  606. }
  607.  
  608.                    ---------- END LISTING I. ----------
  609. .pa
  610.  
  611.  
  612.                             Unix Comments
  613.  
  614.     Two users had responses to previous comments about Unix. Tim Prince 
  615.  
  616.  
  617.  
  618. of Marblehead, MA writes:
  619.  
  620.     "As  a  new UNIX user I find some of the subjects  raised  in  your 
  621.  
  622. column  this  month [April] interesting.   Certainly,  in  comparison  with 
  623.  
  624. VAX/VMS, there is a lack of discipline in adhering to uniform standards for 
  625.  
  626. a  user  interface.   This is the almost inevitable result of the way  UNIX 
  627.  
  628. evolved  as  the product of the work of various  organizations.   Also  the 
  629.  
  630. volume  of official documentation is much less,  but if you count the  many 
  631.  
  632. good  books available from third parties,  the comparison will soon go  the 
  633.  
  634. other  way...Unix has collected a set of useful information into a pair  of 
  635.  
  636. volumes which the individual can afford to own."
  637.  
  638.     He adds:  "I have spent nearly 20 years learning things about GCOS, 
  639.  
  640. which  has  all  the faults of which UNIX is accused without  many  of  the 
  641.  
  642. advantages.  This operating system will soon disappear from the face of the 
  643.  
  644. earth,  making our knowledge of its quirks so much non-biodegradable mental 
  645.  
  646. trash.   What  is learned about UNIX is more likely to remain useful  after 
  647.  
  648. the current hardware is gone."
  649.  
  650.     Mike Meyers writes:
  651.  
  652.     "...I tend to agree with most of the things you've said about Unix.  
  653.  
  654. The documentation is, at best, terse.  What's worse, it's either missing or 
  655.  
  656. wrong  in many places.   To top it off,  most of it assumes that  you  have 
  657.  
  658. access to the source,  and are a good computer scientist.   To make matters 
  659.  
  660. still worse,  there really isn't an on-line documentation system.  What you 
  661.  
  662. have is an interactive manual printer.   It is very definitely not friendly 
  663.  
  664. to the naive user.   The best description I have run across is that Unix is 
  665.  
  666. expert-friendly.   If  you know it,  it's going to be great.   If you don't 
  667.  
  668. know it, well, that's just too bad."
  669.  
  670.     These  two viewpoints are not mutually exclusive;  Unix is  expert-
  671.  
  672.  
  673.  
  674. friendly and beginner-hostile;  many of the Unix systems such as 'man'  and 
  675.  
  676.  
  677.  
  678. 'mail' are primitive, but this bothers some users less than others.  
  679.  
  680.  
  681.  
  682.  
  683.                                 Conclusion
  684.  
  685.     This column exists for the purpose of discussing C and Unix as they 
  686.  
  687.  
  688.  
  689. exist with the problems they have.   As stated emphatically above,  C and C 
  690.  
  691.  
  692.  
  693. input-output  are independent concepts.  However,  it is  the  input-output 
  694.  
  695.  
  696.  
  697. library  that users generally deal with,  and deviations from it which they 
  698.  
  699.  
  700.  
  701. complain about.   Therefore,  such a discussion has a place here.  I invite 
  702.  
  703.  
  704.  
  705. Mr.  Evenden and other readers to submit any code which illustrates how  to 
  706.  
  707.  
  708.  
  709. deal  with raw input-output in C under CP/M,  Unix or under other operating 
  710.  
  711.  
  712.  
  713. systems.  
  714.  
  715.     In this column,  we have considered some user comments about C/Unix 
  716.  
  717.  
  718.  
  719. based on several letters received recently.   I would be interested to hear 
  720.  
  721.  
  722.  
  723. what  others  think about this ongoing discussion,  as well  as  follow  up 
  724.  
  725.  
  726.  
  727. comments from those readers represented here.
  728.