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