Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!amdahl!pyramid!hplabs!hp-pcd!hplsla!jima From: jima@hplsla.HP.COM ( Jim Adcock) Newsgroups: comp.lang.c++ Subject: Re: access functions Message-ID: <6590046@hplsla.HP.COM> Date: 25 Apr 88 19:59:32 GMT References: <11152@mimsy.UUCP> Organization: HP Lake Stevens, WA Lines: 37 | I should also mention that there is no performance penalty for access | functions. If they are expanded inline the generated code is exactly | the same as reading a public instance variable. Not strictly true. It is not uncommon for the compiler to assign ["unnecessarily"] to an intermediate variable in order to "make sure" that the value of the underlaying variable that the access function protects does not "accidentally" get changed. The compiler seems to do this whenever it is unsure whether or not that underlaying variable might get clobbered. Again, my only point is that I do not believe one should say uncategorically that access functions should be used everywhere. Someone try to explain to me what great advantages access functions have in the following [trivialized to the ridiculous] example ???: class IntVal { private: int val; public: void setValue(int aval) {val = aval;} int value() {return val;} }; verses class IntVal { public: value; }; But if even this one example shows that "use access functions everywhere" statement is overreaching, haven't I shown its converse, namely that there ARE situations where one should consider NOT using access functions ??? [I still don't like the use of mag/phase rep for complex numbers :-]