[fpc-devel] Fwd: New Issue: Accessibility Declarations for FreePascal
Tomas Hajny
XHajT03 at hajny.biz
Tue Oct 20 16:56:44 CEST 2026
On 2026-10-19 18:38, Martin Frb via fpc-devel wrote:
Hi,
> Can someone comment on this?
>
> Do we have C-like distinction between access and visible?
>
> I would think not?
>
> If you can access it you can see it, and vice versa?
> I can't think of any other case (i.e. where an identifier would be
> hidden by something that you can't access like in the example below)
>
> We do have the reverse, that a public property/function can expose a
> private type (but not the name of the type, just its "content"
> (enum/members))
Equally to you, I don't think that FPC could distinguish accessibility
from visibility. Obviously, there are cases when some declaration /
definition "hides" something by using the same identifier for something
else, but there are still ways allowing you to access the original
"hidden" declaration. As an example, you may define a method M in some
class (TC1), then create a new method with the same name of M in a child
class (TC2) effectively meaning that you cannot access the original
method M defined in TC1 from within TC2 directly, but you can still
access it by typecasting the variable of type TC2 to TC1 and calling it
that way. However, Similarly, using the same identifier in outer scope
and in an inner scope (e.g. a global and local variables with the same
name) "hides" the global identifier within the inner scope (e.g. in a
procedure) in the sense that you cannot access it using the original
identifier any longer, but you can still access it using a fully
qualified name by prefixing it with a unit or program name.
Tomas
> -------- Forwarded Message --------
>
> Martin,
>
> Last week, while we were discussing the FreePascal accessibility
> declarations, I began to wonder whether the private/strict
> private/protected/strict protected keywords really were accessibility
> values or visibility values. In the reference manual, it uses both
> terms interchangeably. It says, "The visibility of the different
> sections is...", but then in the text for each value, it uses verbiage
> like "can be accessed". In C++, there are situtations where
> visibility vs. accessibility is an important distinction. My go-to to
> expose this is hiding rules. For example:
>
>> int foo = 1;
>>
>> class C {
>> private:
>> int foo {2};
>> };
>>
>> class D : public C {
>> public:
>> void func()
>> {
>> // illegal because C::foo is visible here, but not accessible.
>> // Because C::foo is visible, it hides ::foo.
>> std::cout << foo << '\n';
>> }
>> };
>
> Or another example:
>
>> class C {
>> public:
>> int foo { 1 };
>> };
>>
>> class D : public C {
>> private:
>> int foo { 2 };
>> };
>>
>> int main()
>> {
>> D obj;
>> // illegal because D::foo is visible here, but not accessible.
>> // Because D::foo is visible here, it hides C::foo.
>> std::cout << obj.foo << '\n';
>> }
>
> My question is: In FreePascal, are there situations like this where
> the private/strict private/protected/strict protected names can hide
> other names at global scope? Or at any "outer" scope, for that
> matter, if these constructs can be declared arbitrarily nested within
> other constructs, like in Ada. If they all can hide names, to my
> mind, that rules out using visibility as any part of the description.
> Instead, if none of them can hide other names, then perhaps all of
> them should be visibility values instead. Or, if it's impossible to
> construct an example in FreePascal that can tell the difference, then
> perhaps I'm just splitting hairs. :)
>
> Regards,
> Todd Allen
More information about the fpc-devel
mailing list