home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 19140 < prev    next >
Encoding:
Text File  |  1993-01-02  |  1.8 KB  |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!dkeisen
  3. From: dkeisen@leland.Stanford.EDU (Dave Eisen)
  4. Subject: Re: Parameter passing & data abstraction
  5. Message-ID: <1993Jan3.015014.2395@leland.Stanford.EDU>
  6. Sender: ?@leland.Stanford.EDU
  7. Organization: Sequoia Peripherals, Inc.
  8. References: <1992Dec30.184135.1963@organpipe.uug.arizona.edu> <1992Dec31.084904@gese.ge14.mdadv.gv.at>
  9. Date: Sun, 3 Jan 93 01:50:14 GMT
  10. Lines: 40
  11.  
  12. In article <1992Dec31.084904@gese.ge14.mdadv.gv.at> sca@gese.ge14.mdadv.gv.at (Petzi Schweda) writes:
  13. >Furthermore highly encapsulate thy data, not exporting any structures:
  14. >    #ifdef MODULE_PRIVATE
  15. >    typedef struct ModuleDataRec
  16. >        {....
  17. >        } ModuleDataRec, *ModulData;
  18. >        #define SetMember(d, v) (*d).member = v; 
  19. >    #else
  20. >    typedef void *ModulData;
  21. >    void SetMember(ModulData d, int v);
  22. >    #endif;
  23.  
  24. I'm as big a fan of information hiding as anyone, but I object
  25. to your using (void *) to represent objects of a certain type.
  26. You lose all of the type checking that prototyping gives you
  27. for no gain.
  28.  
  29. The public interface should be quite aware that ModulData is
  30. a pointer to a struct ModuleDataRec. It should have no idea
  31. what any of the fields in such a struct look like, but there
  32. is no need to tell it.
  33.  
  34. Something like:
  35.  
  36.     typedef struct ModuleDataRec ModuleDataRec, *ModulData;
  37.     void SetMember(ModulData d, int v);
  38.  
  39.     #ifdef MODULE_PRIVATE
  40.     struct ModuleDataRec
  41.         {....
  42.         } ModuleDataRec, *ModulData;
  43.         #define SetMember(d, v) (*d).member = v; 
  44.     #endif;
  45.  
  46.  
  47. -- 
  48. Dave Eisen                               Sequoia Peripherals: (415) 967-5644
  49. dkeisen@leland.Stanford.EDU              Home:                (415) 321-5154
  50.        There's something in my library to offend everybody. 
  51.           --- Washington Coalition Against Censorship
  52.