Hi, Aare Tali!
On 11 Apr 97 04:05:00 you wrote to Erik Jakobsen
> AT> static void x::xx(void)
> AT> {
> AT> }
> this is not a valid c++ declaration or definition.
AT> Of course, and that's what i dislike. I wanted to restrict access
AT> to x::xx (being already private) to this module only. For ordinary
AT> functions that's OK (put 'static' there and entry point will be
AT> hidden), but methods are special in that point for some reason unknown
AT> to me.
You couldn't exploit it anyway. For any module defining class members you
will include the header defining the class structure. And xx will be there.
So the module will be able to call it. (OTOH if you could force static,
you'd get an error at link time.)
And relating to member functions the `static' keyword has a new meaning (did
anyone count how much different things it does?). A member function with
static attribute will not recieve a this member, so it can be called by its
own, not relating to an instance.
AT> I'll explain it a bit more. Private methods are visible to anyone
AT> as far as linker is concerned. Compiler effectively restricts access
AT> to private methods at the source level. But linker doesn't have a
AT> foggiest (OK, no idea at all what all this is about) and there is
AT> still a way to access private methods from outside. If you have a bit
AT> assembly knowledge and know how compiler mangles names, you can access
AT> them.
Or if it's virtual you can simply call it through the VMT. :)
AT> Of course, usually it's not needed. But i consider it same as
AT> having root password hard-coded to 'root' with the lame excuse that
AT> 'usually noone wants to be root unless absolutely necessary'.
That's not a good parabola. But let's see it closer. Unix is said to be safe.
You have a root account, protected with a password. So you say your files
belonging to root are safe from reading by others. The 700 privilege grants
that.
But if I can boot another opsystem on that machine (or remove the HD and
place in another machine) I can read your files though. a simple disk editor
will do the task. Can unix be blamed for that? IMO no. Nor can C++ be
blamed for your practices using asm to call the private members. You just
step out of its reach.
If you're really annoyed, you can write a simple program that removes PUBDEF
records from a .OBJ file, so getting the same behavior use of static would do
for you.
Paul
... I drink, therefore I am.
--- OS/2 Warp
---------------
* Origin: The FlintStones' Cave in BedRock (2:371/20)
|