C style 'static' functions

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 19 04:31:32 PDT 2017


On 2017-07-19 09:22, John Burton wrote:
> In C I can declare a function 'static' and it's only visible from within 
> that implementation file. So I can have a static function 'test' in 
> code1.c and another non static function 'test' in utils.c and assuming a 
> suitable prototype I can use 'test' in my program and the one in code1.c 
> will not interfere.
> 
> In D it seems that declaring functions as static in a module does not 
> affect visibility outside of a module. So if I declare a static function 
> in one module with a specific name that is just used in internally for 
> the implementation, and then define a function with the same name in 
> another module that is intended to by 'exported' then in my main program 
> they still conflict and I have to take steps to avoid this.
> 
> It looked as if I could use 'private' instead of static but although 
> this prevents me from calling the "private" function, it still conflicts 
> with the one I want to call.
> 
> In C++ I could use static or an anonymous namespace for implementation 
> functions, but there doesn't seem to be anything similar in D.
> Is there any way to achieve what I want in D (Private implementation 
> functions)

I think it would be easier if you provide a small code example of what 
you want to achieve.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list