Some user-made C functions and their D equivalents

kdevel kdevel at vogtner.de
Thu Jul 28 13:06:03 UTC 2022


On Thursday, 28 July 2022 at 12:25:05 UTC, pascal111 wrote:
> [...]
>> 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,

"Code works" and "Code is correct" are two distinct categories. 
The compiler's warnings show that your code is not correct and 
not that it will necessarily not work. Incorrect code may work 
accidentally.

As a (future) software developer you are required to not just 
produce code that "works" "with no problem" but also code that is 
correct. "Correct" here means that the code adheres to the 
specifications of the language.

Writing incorrect code is like "fixing" a "broken" fuse with tin 
foil.

> 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.

The incorrectness of your C code does not depend on the compiler 
brand.


More information about the Digitalmars-d-learn mailing list