home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13204 < prev    next >
Encoding:
Internet Message Format  |  1992-09-02  |  1.1 KB

  1. Path: sparky!uunet!olivea!decwrl!borland.com!pete
  2. From: pete@genghis.borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: GOTO, was: Tiny proposal for na
  5. Message-ID: <1992Sep2.155510.4274@genghis.borland.com>
  6. Date: 2 Sep 92 15:55:10 GMT
  7. References: <2318@devnull.mpd.tandem.com> <rmartin.715001372@thor> <4192@papaya.bbn.com>
  8. Sender: news@borland.com (News Admin)
  9. Organization: Borland International
  10. Lines: 40
  11. Originator: pete@genghis.borland.com
  12.  
  13. In article <4192@papaya.bbn.com> cbarber@bbn.com (Chris Barber) writes:
  14. >
  15. >My way:
  16. >
  17. >void foo(void)
  18. >{
  19. >    FILE *fp = NULL ;
  20. >    char *data = NULL ;
  21. >
  22. >    if ((fp = fopen("foo", "r")) == NULL)
  23. >        goto cleanup ;
  24. >
  25. >    data = malloc(DATASIZE) ;
  26. >
  27. >    if (DoStuff(fp, data) == ERROR)
  28. >        goto cleanup ;
  29. >
  30. >    DoMoreStuff(data) ;
  31. >
  32. > cleanup:
  33. >    if (fp)
  34. >        (void)fclose(fp) ;
  35. >    if (data)
  36. >        free(data) ;
  37. >}
  38. >
  39.  
  40. C++ version:
  41.  
  42. void foo()
  43. {
  44.     ifstream input( "foo" );
  45.     DataObject data;
  46.     if( data.doStuff( input ) == ERROR )
  47.         return;
  48.     data.doMoreStuff();
  49. }
  50.  
  51.     Let the compiler do the work...
  52.     -- Pete
  53.