On Thursday, 28 July 2022 at 12:15:19 UTC, kdevel 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
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`.
"fix" function is the C version of BASIC standard one I made,
it's the equivalent of "trunc" in D, but the code I programmed
for "fix" was with TC++ , and it worked in DOS emulators with no
problem, I have no idea how gcc will treat my code, but I think
you are right that some other compilers will refuse such code,
because VC++ 6 refused many of these functions codes I programmed
with TC++ compiler.