|
![](/i/fill.gif) |
Darren New <dne### [at] san rr com> wrote:
> > Could you give a concrete example of a compiler, of any OO language,
> > which will only *warn* (rather than give an error message) if you try to
> > access a member variable specifically marked as private from the outside?
> Sure. C# or Java. You get this warning that says "this won't compile."
Wait. The compiler gives a *warning* which says "this won't compile"?
If it's just a warning, and not an error, it means that it will compile
it anyways? Isn't that contradictory?
> Another example is, as I've been saying, C++. The compiler warns (and won't
> compile) if you access the private variable by name
I get no warning if I try to access a private member. I get an error.
There's a big categorical difference.
>, but not if you
> intentionally or accidentally access the private variable by address.
You can't access the private variable by address. Not according to the
standard. If you can, then that can be considered a non-standard compiler
extension.
And trashing memory, triggering UB, is not the same thing as "accessing
a member variable". The effect may be the same as accessing in one compiler,
but might not be in another. You are not *really* accessing it. You are
just abusing compiler and system specific undefined behavior.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |