Internal linkage - equivalent of C++ global static and anonymous namespaces

2014-06-12 Thread Francesco Cattoglio via Digitalmars-d
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?


Re: Internal linkage - equivalent of C++ global static and anonymous namespaces

2014-06-12 Thread Kagamin via Digitalmars-d

Why private members can't have internal linkage?


Re: Internal linkage - equivalent of C++ global static and anonymous namespaces

2014-06-12 Thread Francesco Cattoglio via Digitalmars-d

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/jlbsreudrapysiaet...@forum.dlang.org?page=2#post-irrbdrxordjawkryvrub:40forum.dlang.org 
and following posts.


Re: Internal linkage - equivalent of C++ global static and anonymous namespaces

2014-06-12 Thread Dicebot via Digitalmars-d

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 :( )


Re: Internal linkage - equivalent of C++ global static and anonymous namespaces

2014-06-12 Thread Jacob Carlborg via Digitalmars-d

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


Re: Internal linkage - equivalent of C++ global static and anonymous namespaces

2014-06-12 Thread Dicebot via Digitalmars-d

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.


Re: Internal linkage - equivalent of C++ global static and anonymous namespaces

2014-06-13 Thread deadalnix via Digitalmars-d

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


Re: Internal linkage - equivalent of C++ global static and anonymous namespaces

2014-06-13 Thread deadalnix via Digitalmars-d

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.