Thread overview | |||||
---|---|---|---|---|---|
|
February 24, 2010 Using C function in Tango - Simple solution? | ||||
---|---|---|---|---|
| ||||
Hi I am new in D. I've the following problem. I want to use a old function out of the C programming language. I'm using D, with the dmd compiler, and the Tango lib. My "dirty" solution is the following: <code> version (Tango) extern (C) int getchar(); void main() { char quit = '\0'; while (quit != 'q') { quit = getchar; } } </code> But I believe the first line is too inconvenient. Are there any better solutions to use C functions with the Tango lib. I'm looking forward to your answers and I would be very happy with a few code exampes. Greetings from Germany Fabian Classen |
February 24, 2010 Re: Using C function in Tango - Simple solution? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Fabian Classen | On 24/02/10 19:46, Fabian Classen wrote:
> Hi
> I am new in D.
> I've the following problem. I want to use a old function out of the C
> programming language. I'm using D, with the dmd compiler, and the Tango
> lib. My "dirty" solution is the following:
>
> <code>
> version (Tango) extern (C) int getchar();
>
> void main() {
> char quit = '\0';
> while (quit != 'q') {
> quit = getchar;
> }
> }
> </code>
>
> But I believe the first line is too inconvenient.
> Are there any better solutions to use C functions with the Tango lib.
>
> I'm looking forward to your answers and I would be very happy with a few
> code exampes.
>
> Greetings from Germany
> Fabian Classen
How about:
----
import tango.stdc.stdio;
----
If you're using tango then there's no need for the version(Tango), unless you plan on supporting phobos too. I'd advise not to do this, as you'll only end up duplicating your efforts, the time's better spent on your actual program :) Plus, should you decide to migrate to D2 at a later date, all these efforts will have been wasted.
|
February 24, 2010 Re: Using C function in Tango - Simple solution? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Clipsham | Am Wed, 24 Feb 2010 19:58:59 +0000 schrieb Robert Clipsham:
> On 24/02/10 19:46, Fabian Classen wrote:
>> Hi
>> I am new in D.
>> I've the following problem. I want to use a old function out of the C
>> programming language. I'm using D, with the dmd compiler, and the Tango
>> lib. My "dirty" solution is the following:
>>
>> <code>
>> version (Tango) extern (C) int getchar();
>>
>> void main() {
>> char quit = '\0';
>> while (quit != 'q') {
>> quit = getchar;
>> }
>> }
>> </code>
>>
>> But I believe the first line is too inconvenient. Are there any better solutions to use C functions with the Tango lib.
>>
>> I'm looking forward to your answers and I would be very happy with a few code exampes.
>>
>> Greetings from Germany
>> Fabian Classen
>
> How about:
>
> ----
> import tango.stdc.stdio;
> ----
>
> If you're using tango then there's no need for the version(Tango), unless you plan on supporting phobos too. I'd advise not to do this, as you'll only end up duplicating your efforts, the time's better spent on your actual program :) Plus, should you decide to migrate to D2 at a later date, all these efforts will have been wasted.
Thank you very much :-)
That's the module I was looking for.
Best wishes!
Fabian Classen
|
Copyright © 1999-2021 by the D Language Foundation