Some user-made C functions and their D equivalents
pascal111
judas.the.messiah.111 at gmail.com
Thu Jul 28 00:07:52 UTC 2022
On Wednesday, 27 July 2022 at 19:07:26 UTC, ryuukk_ wrote:
> On Wednesday, 27 July 2022 at 18:19:34 UTC, pascal111 wrote:
>> I made a library of some useful functions while I was studying
>> C, and I'm curious to know if D has equivalents or some ones
>> for some of my functions, or I have to retype 'em again in D.
>>
>> The library link:
>> https://github.com/pascal111-fra/turbo-c-programs/blob/main/COLLECT2.H
>
> D ships with libc so everything in there is available
>
> ```C
> #include<stdio.h>
> #include<string.h>
> #include<stdlib.h>
> #include<ctype.h>
> #include<math.h>
> ```
>
>
> In d the equivalent imports:
>
> ```D
> import core.stdc.stdio;
> import core.stdc.string;
> import core.stdc.stdlib;
> import core.stdc.ctype;
> import core.stdc.math;
> ```
Ok, but before that, I faced a problem when I tried to make my
module. I tried to make a test. I made a testing module called
"dcollect.d" and I put it in this path on my Ubuntu
"/usr/lib/gcc/x86_64-linux-gnu/11/include/d".
module dcollect;
import std.stdio;
int foo22()
{
return 5;
}
Then I called "foo22" in a testing program and found an error
like (this one in another try by telling code::blocks about local
searching folder for the compiler I put the module in) "||===
Build: Debug in temp (compiler: GDC D Compiler) ===|
/home/pascal111/My Projects/D/temp/hello.d|23|undefined reference
to `_D8dcollect5foo22FZi'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 1
second(s)) ===|"
The testing program:
module main;
import std.stdio;
import std.string;
import std.conv;
import dcollect;
int main(string[] args)
{
string ch;
try{
ch=readln();
ch=strip(ch);
if(to!int(ch)<0)
throw new Exception ("You entered negative number!");}
catch (Exception e){
writeln(e.msg);}
writeln(foo22());
return 0;
}
More information about the Digitalmars-d-learn
mailing list