C style 'static' functions
John Burton via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jul 19 00:22:48 PDT 2017
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)
More information about the Digitalmars-d-learn
mailing list