mgardi@watserv1.waterloo.edu (Mutual Life) (01/16/90)
Could someone give me a short description of how the compiler restricts access to private/protected elements? When I look at the C code generated, I don't see any difference in the code regardless of where I place the data. p. Peter DeVries Mutual Life of Canada c/o mgardi@watdcsu (519) 888-3523 (416) 972-0594
ark@alice.UUCP (Andrew Koenig) (01/16/90)
In article <626@watserv1.waterloo.edu>, mgardi@watserv1.waterloo.edu (Mutual Life) writes: > Could someone give me a short description of how the compiler restricts > access to private/protected elements? > When I look at the C code generated, I don't see any difference in > the code regardless of where I place the data. > p. Correct. Visibility restrictions affect only whether or not a given program is legal. That is, the compiler checks visibility during compilation and either accepts the program or not. Changing visibility should not (and in AT&T C++ does not) affect the object code generated for a program. This is an important property for debugging. If you're writing a class that doesn't work, and you didn't design debugging scaffolding into the class from the beginning, you often have to make members public temporarily so you can print their values. It would be a real pain if this were to change the behavior of the program. -- --Andrew Koenig ark@europa.att.com
shap@delrey.sgi.com (Jonathan Shapiro) (01/17/90)
In article <626@watserv1.waterloo.edu> mgardi@watserv1.waterloo.edu (Mutual Life) writes: >Could someone give me a short description of how the compiler restricts >access to private/protected elements? The restriction is only applied by the compiler at compile time. Since it has seen the declarations, it knows what you are allowed to do.
davidc@vlsisj.VLSI.COM (David Chapman) (01/18/90)
In article <626@watserv1.waterloo.edu> mgardi@watserv1.waterloo.edu (Mutual Life) writes: >Could someone give me a short description of how the compiler restricts >access to private/protected elements? > >When I look at the C code generated, I don't see any difference in >the code regardless of where I place the data. It should look the same because (presumably) you're doing the same thing in each case. If you try to access elements without the "privilege" to do so, the compiler simply refuses and prints an error message. This checking doesn't get out to the generated C code (with cfront as opposed to native compilers like Zortech) because you aren't modifying that file. At least I hope you're not. :-) The "prevention" is done by the compiler at compile time and has no effect at run time. You can still do just as much damage as with C. :-) -- David Chapman {known world}!decwrl!vlsisj!fndry!davidc vlsisj!fndry!davidc@decwrl.dec.com