digitalmars.D.learn - how to declare C's static function?
- aki (14/14) Mar 27 2016 Hello,
- Rikki Cattermole (2/2) Mar 27 2016 Do you need it to use extern(C)?
- aki (9/11) Mar 27 2016 Yes, I do need extern(C) for some reason like:
- Rikki Cattermole (5/17) Mar 27 2016 Okay so you're needing extern(C).
- aki (6/8) Mar 27 2016 So... You mean there are no way to declare functions
- Adam D. Ruppe (5/7) Mar 28 2016 alas, no, even if it is private it can conflict on the outside
- aki (5/12) Mar 28 2016 Thank you for clarify.
- Mike Parker (3/8) Mar 28 2016 Seems to be fixed in the latest beta (finally):
- aki (2/12) Mar 28 2016 Good news!
- Jacob Carlborg (5/17) Mar 28 2016 Can you declare the function as "package" in one module and import it
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.
Mar 27 2016
Do you need it to use extern(C)? Because if you don't, just drop that. D's mangling will fix it.
Mar 27 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.
Mar 27 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: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.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.
Mar 27 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.
Mar 27 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.
Mar 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:Thank you for clarify. Now I know I have to change the name as a result. Thanks, aki.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.
Mar 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:Seems to be fixed in the latest beta (finally): http://dlang.org/changelog/2.071.0.html#dip22So... 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).
Mar 28 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:Good news!On Monday, 28 March 2016 at 04:53:19 UTC, aki wrote:Seems to be fixed in the latest beta (finally): http://dlang.org/changelog/2.071.0.html#dip22So... 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).
Mar 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
Mar 28 2016