Some user-made C functions and their D equivalents

kdevel kdevel at vogtner.de
Thu Jul 28 12:15:19 UTC 2022


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

1. What exact purpose do these

```
/******************************************/
```

have?

2.
```
double fix(double x)
{

double y,* z;

y=modf(x,z);
y=*z;

return y;

}
```
Besides the remarkable formatting there is an issue with the 
code. According to the manual the modf function

```
double modf(double x, double *iptr);
```

stores "The integral part [of x] [...] in the location pointed to 
by iptr." If you ask the compiler for help (e.g. `gcc -Wall 
-pedantic`) it will tell you what's wrong:

```
ofix.c: In function 'fix':
ofix.c:7:3: warning: 'z' is used uninitialized [-Wuninitialized]
     7 | y=modf(x,z);
       |   ^~~~~~~~~
ofix.c:5:12: note: 'z' was declared here
     5 | double y,* z;
       |            ^
```

I would also like to complain about the double assignment to `y`.


More information about the Digitalmars-d-learn mailing list