How to use a function without their sources

anonymous anonymous at example.com
Fri Jan 18 12:20:29 PST 2013


On Friday, 18 January 2013 at 17:47:42 UTC, nazriel wrote:
> lib.d:
>
> extern(C) void printf(const char*, ...);
>
> void foo() {
> 	printf("%s".ptr, "hi".ptr);	
> }
>
> test.d:
>
> extern(C) void _D3lib3fooFZv();
>
> void main() {
> 	_D3lib3fooFZv();
> }

On Friday, 18 January 2013 at 18:18:07 UTC, Andrej Mitrovic wrote:
> That's a *terrible* idea, you are calling a D function using 
> the C
> convention, you're going to have all sorts of problems. 
> extern(D) is
> not just used for mangling, it's also used for designating how
> parameters are passed to and results are returned from a 
> function (via
> stack/registers).

On Friday, 18 January 2013 at 18:50:01 UTC, nazriel wrote:
> It's valid example as long as you objump object file.

It's a bad example. You just got lucky in that the calling 
conventions match in that particular case.


More information about the Digitalmars-d-learn mailing list