C style 'static' functions
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 19 10:25:18 PDT 2017
On Wednesday, 19 July 2017 at 15:28:50 UTC, Steven Schveighoffer
wrote:
> On 7/19/17 8:16 AM, Petar Kirov [ZombineDev] wrote:
>> On Wednesday, 19 July 2017 at 12:11:38 UTC, John Burton wrote:
>>> On Wednesday, 19 July 2017 at 12:05:09 UTC, Kagamin wrote:
>>>> Try a newer compiler, this was fixed recently.
>>>
>>> Hmm it turns out this machine has 2.0.65 on which is fairly
>>> ancient. I'd not realized this machine had not been updated.
>>>
>>> Sorry for wasting everyones' time if that's so, and thanks
>>> for the help.
>>
>> Just for the record, private is the analog of C's static. All
>> private free and member functions are callable only from the
>> module they are defined in. This is in contrast with C++,
>> Java, C# where private members are visible only the class they
>> are defined in.
>
> I'm not so sure of that. Private functions still generate
> symbols. I think in C, there is no symbol (at least in the
> object file) for static functions or variables.
>
> You could still call a private function in a D module via the
> mangled name I believe.
>
> -Steve
>
> Note: not 100% sure of all this, but this is always the way
> I've looked at it.
You're probably right about the current implementation, but I was
talking about the intended semantics. I believe that with DIP45,
only functions and global variables annotated with the export
storage class would necessary have externally visible symbols.
Also, consider this enhancement request (which I think Walter and
Andrei approve of) -
https://issues.dlang.org/show_bug.cgi?id=13567 - which would be
doable only if private functions don't have externally visible
symbols.
See also: https://issues.dlang.org/show_bug.cgi?id=9893.
More information about the Digitalmars-d-learn
mailing list