home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!dkeisen
- From: dkeisen@leland.Stanford.EDU (Dave Eisen)
- Subject: Re: Parameter passing & data abstraction
- Message-ID: <1993Jan3.015014.2395@leland.Stanford.EDU>
- Sender: ?@leland.Stanford.EDU
- Organization: Sequoia Peripherals, Inc.
- References: <1992Dec30.184135.1963@organpipe.uug.arizona.edu> <1992Dec31.084904@gese.ge14.mdadv.gv.at>
- Date: Sun, 3 Jan 93 01:50:14 GMT
- Lines: 40
-
- In article <1992Dec31.084904@gese.ge14.mdadv.gv.at> sca@gese.ge14.mdadv.gv.at (Petzi Schweda) writes:
- >Furthermore highly encapsulate thy data, not exporting any structures:
- > #ifdef MODULE_PRIVATE
- > typedef struct ModuleDataRec
- > {....
- > } ModuleDataRec, *ModulData;
- > #define SetMember(d, v) (*d).member = v;
- > #else
- > typedef void *ModulData;
- > void SetMember(ModulData d, int v);
- > #endif;
-
- I'm as big a fan of information hiding as anyone, but I object
- to your using (void *) to represent objects of a certain type.
- You lose all of the type checking that prototyping gives you
- for no gain.
-
- The public interface should be quite aware that ModulData is
- a pointer to a struct ModuleDataRec. It should have no idea
- what any of the fields in such a struct look like, but there
- is no need to tell it.
-
- Something like:
-
- typedef struct ModuleDataRec ModuleDataRec, *ModulData;
- void SetMember(ModulData d, int v);
-
- #ifdef MODULE_PRIVATE
- struct ModuleDataRec
- {....
- } ModuleDataRec, *ModulData;
- #define SetMember(d, v) (*d).member = v;
- #endif;
-
-
- --
- Dave Eisen Sequoia Peripherals: (415) 967-5644
- dkeisen@leland.Stanford.EDU Home: (415) 321-5154
- There's something in my library to offend everybody.
- --- Washington Coalition Against Censorship
-