Program to check whether a field is private

Is it possible to check in a program whether a given variable in a class in some other program is private or not by, for instance, using try and catch?
Privacy violation is a compile time error, not a run-time error.

What do you mean by "other program"?

By that I mean one that I could include in the first program similiarly to libraries. Perhaps I shouldn't have called it an "other program" since it would lack the main function.
Last edited on
you can open the source code file and do a simple parse of it? (you have to track maybe 4 or 5 things... public and private keywords, class and struct keywords, and {} pairs related to the class and structs).

private is a language tool to prevent accidental access where it could produce bugs, and as said already it is a compile time error. Compiled libraries are a tricky subject as they may not even have originated in a language that has these concepts (public and private). Like C, for example, has no concept of private. Instead, a library is supposed to expose to the user what is allowed to be used, and all else is hidden simply via the limitation that anything not exposed is not (easily) accessible or even (known about?) without the source code behind it. If its not in the interface, its private :)

Last edited on
I could of course go through the whole file while treating it as pure text, but isn't there a different way?
Full disclosure, there's most likely another way. There's a caveat or two, though.

Firstly, if you ever actually did this in real life, you'd be slapped in the face and then fired.

However, this is certainly an XY problem.
http://xyproblem.info/
What is the problem you are actually trying to solve?
Last edited on
I could of course go through the whole file while treating it as pure text, but isn't there a different way?

Yes, there are other ways. Im with him ^^^ what are you *really* trying to accomplish?
Compilers are not the only programs that read source code.

There is, for example Doxygen https://www.doxygen.nl/index.html
It does produce a "human readable" summary from source code.
Topic archived. No new replies allowed.