Thread overview
how to declare C's static function?
Mar 28, 2016
aki
Mar 28, 2016
Rikki Cattermole
Mar 28, 2016
aki
Mar 28, 2016
Rikki Cattermole
Mar 28, 2016
aki
Mar 28, 2016
Adam D. Ruppe
Mar 28, 2016
aki
Mar 29, 2016
Mike Parker
Mar 29, 2016
aki
Mar 28, 2016
Jacob Carlborg
March 28, 2016
Hello,

When I porting legacy app. written in C to D,
I have a problem.

file a.d:
extern (C) private void foo() {}

file b.d:
extern (C) private void foo() {}

 Error 1: Previous Definition Different : _foo

In C language, "static void foo(){}" does not
export the symbol out side the compilation unit.
In D, the function foo() above conflicts even if
it is private. How can I declare C's static function?

Regards,
Aki.

March 28, 2016
Do you need it to use extern(C)?
Because if you don't, just drop that. D's mangling will fix it.

March 28, 2016
On Monday, 28 March 2016 at 04:12:56 UTC, Rikki Cattermole wrote:
> Do you need it to use extern(C)?
> Because if you don't, just drop that. D's mangling will fix it.

Yes, I do need extern(C) for some reason like:
alias Hook = extern(C) void function();
void sethook(Hook func) {
    ...
}
... sethook(&foo) ...

Some function expects such a function as an argument.

Aki.

March 28, 2016
On Monday, 28 March 2016 at 04:27:27 UTC, aki wrote:
> On Monday, 28 March 2016 at 04:12:56 UTC, Rikki Cattermole wrote:
>> Do you need it to use extern(C)?
>> Because if you don't, just drop that. D's mangling will fix it.
>
> Yes, I do need extern(C) for some reason like:
> alias Hook = extern(C) void function();
> void sethook(Hook func) {
>     ...
> }
> ... sethook(&foo) ...
>
> Some function expects such a function as an argument.
>
> Aki.

Okay so you're needing extern(C).
I was assuming they were just internal functions.

You have two choices. Change the name in code (so manual mangling) or use pragma(mangle, ...) to change it instead.
March 28, 2016
On Monday, 28 March 2016 at 04:33:06 UTC, Rikki Cattermole wrote:
> You have two choices. Change the name in code (so manual mangling) or use pragma(mangle, ...) to change it instead.

So... You mean there are no way to declare functions
without exporting the symbol?
There are so many instances to change..
But thanks any way.

Aki.

March 28, 2016
On 2016-03-28 06:02, aki wrote:
> Hello,
>
> When I porting legacy app. written in C to D,
> I have a problem.
>
> file a.d:
> extern (C) private void foo() {}
>
> file b.d:
> extern (C) private void foo() {}
>
>   Error 1: Previous Definition Different : _foo
>
> In C language, "static void foo(){}" does not
> export the symbol out side the compilation unit.
> In D, the function foo() above conflicts even if
> it is private. How can I declare C's static function?

Can you declare the function as "package" in one module and import it into the other module?

-- 
/Jacob Carlborg
March 28, 2016
On Monday, 28 March 2016 at 04:53:19 UTC, aki wrote:
> So... You mean there are no way to declare functions
> without exporting the symbol?

alas, no, even if it is private it can conflict on the outside (so stupid btw).

Is it all the same function being referenced? Just importing from there would be ok.

March 28, 2016
On Monday, 28 March 2016 at 14:40:40 UTC, Adam D. Ruppe wrote:
> On Monday, 28 March 2016 at 04:53:19 UTC, aki wrote:
>> So... You mean there are no way to declare functions
>> without exporting the symbol?
>
> alas, no, even if it is private it can conflict on the outside (so stupid btw).
>
> Is it all the same function being referenced? Just importing from there would be ok.

Thank you for clarify.
Now I know I have to change the name as a result.

Thanks,
aki.

March 29, 2016
On Monday, 28 March 2016 at 14:40:40 UTC, Adam D. Ruppe wrote:
> On Monday, 28 March 2016 at 04:53:19 UTC, aki wrote:
>> So... You mean there are no way to declare functions
>> without exporting the symbol?
>
> alas, no, even if it is private it can conflict on the outside (so stupid btw).
>

Seems to be fixed in the latest beta (finally):

http://dlang.org/changelog/2.071.0.html#dip22
March 29, 2016
On Tuesday, 29 March 2016 at 01:04:50 UTC, Mike Parker wrote:
> On Monday, 28 March 2016 at 14:40:40 UTC, Adam D. Ruppe wrote:
>> On Monday, 28 March 2016 at 04:53:19 UTC, aki wrote:
>>> So... You mean there are no way to declare functions
>>> without exporting the symbol?
>>
>> alas, no, even if it is private it can conflict on the outside (so stupid btw).
>>
>
> Seems to be fixed in the latest beta (finally):
>
> http://dlang.org/changelog/2.071.0.html#dip22

Good news!