www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Internal linkage - equivalent of C++ global static and anonymous

reply "Francesco Cattoglio" <francesco.cattoglio gmail.com> writes:
Yesterday I discovered that a global static variable in D is just 
a global variable, with no special rule about symbol visibility 
and such.

I've scrolled quickly through old discussions on the NG and read 
the relevant DIP: http://wiki.dlang.org/DIP22
It seems to me that nobody thought about reusing the module 
keyword for declaring symbols with internal linkage. It would 
look like:

file foo.d:
     module foo; // module declaration
     module uint cantSeeMe; // internal linkage attribute, hidden 
symbol
     private uint can_See_Me; // private, but symbol still visible

AFAIK, module keyword right now is only used for module 
declaration, and is not valid anywhere else. Would it make sense 
to use it in this context, too?
Jun 12 2014
next sibling parent reply "Kagamin" <spam here.lot> writes:
Why private members can't have internal linkage?
Jun 12 2014
parent Jacob Carlborg <doob me.com> writes:
On 12/06/14 11:48, Kagamin wrote:
 Why private members can't have internal linkage?

It's currently possible to access private symbols through pointers. -- /Jacob Carlborg
Jun 12 2014
prev sibling next sibling parent "Francesco Cattoglio" <francesco.cattoglio gmail.com> writes:
On Thursday, 12 June 2014 at 09:48:30 UTC, Kagamin wrote:
 Why private members can't have internal linkage?

There has been some discussion about a few corner cases, see http://forum.dlang.org/thread/jlbsreudrapysiaetyrp forum.dlang.org?page=2#post-irrbdrxordjawkryvr b:40forum.dlang.org and following posts.
Jun 12 2014
prev sibling next sibling parent "Dicebot" <public dicebot.lv> writes:
On Thursday, 12 June 2014 at 09:48:30 UTC, Kagamin wrote:
 Why private members can't have internal linkage?

tl; dr: because private provides zero guarantees that symbol won't be referenced in ABI context. It only controls direct language level access. It can possibly be done with analysis of all indirections but effort is not worth the gain. I think getting --gc-sections working out of the box is more worthy goal ( unfortunately last PR from Martin had no practical effect here :( )
Jun 12 2014
prev sibling next sibling parent "Dicebot" <public dicebot.lv> writes:
On Thursday, 12 June 2014 at 14:23:59 UTC, Jacob Carlborg wrote:
 On 12/06/14 11:48, Kagamin wrote:
 Why private members can't have internal linkage?

It's currently possible to access private symbols through pointers.

And aliases with different qualifiers. And via return values. And with pretty much anything that does not require to type symbol identifier explicitly.
Jun 12 2014
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Thursday, 12 June 2014 at 14:48:41 UTC, Dicebot wrote:
 On Thursday, 12 June 2014 at 14:23:59 UTC, Jacob Carlborg wrote:
 On 12/06/14 11:48, Kagamin wrote:
 Why private members can't have internal linkage?

It's currently possible to access private symbols through pointers.

And aliases with different qualifiers. And via return values. And with pretty much anything that does not require to type symbol identifier explicitly.

http://blog.omega-prime.co.uk/?p=121
Jun 13 2014
prev sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Thursday, 12 June 2014 at 14:23:59 UTC, Jacob Carlborg wrote:
 On 12/06/14 11:48, Kagamin wrote:
 Why private members can't have internal linkage?

It's currently possible to access private symbols through pointers.

You don't need a symbol in the object file for that.
Jun 13 2014